Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8807939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:29:35+00:00 2026-06-14T02:29:35+00:00

I am having an issue with this program. I need it to ask for

  • 0

I am having an issue with this program. I need it to ask for a user id then ask for book code and then the cost of a book. An individual can enter an unknown number of books. the program needs to then calculate the individual students book total and then ask another student who does the same. the program must then display the grand totals and total number of books. I cant seem to figure out what to use to be able to keep track of the individual students entries. I would be able to do this from what I was reading about arrays. But we are not to that point yet. The professor wants us to do this with a loop. I am so lost, any help would be awesome.

#include <iostream>
#include <iomanip>

using namespace std;
int main ()
{
    //Declare Variables.
    int student_id;
    char book_code;
    float book_cost;
    float tax_amount;
    float book_subtotal;
    const int SENTINEL = -9999;
    const double TAX = .07;
    float total_book_cost;
    int number_books;
    int total_books_sold;
    double grand_total;

    //Set Variables to Zero.
    number_books = 0;
    total_book_cost = 0.00;
    grand_total = 0.00;

    //Set Decimal to two places.
    cout << fixed << showpoint;
    cout << setprecision(2);

    //Input Data
    cout<<"Please enter your Student ID, then press enter."<<endl;
    cin>>student_id;
    while (student_id != SENTINEL){
        cout<<"Please enter your Book Code, then press enter."<<endl;
        cin>>book_code;
        cout<<"Please enter the cost of the book, then press enter."<<endl;
        cout<<"$"; cin>>book_cost;
        tax_amount = book_cost * TAX;
        book_subtotal = book_cost + tax_amount;
        total_book_cost += book_subtotal;
        number_books++;
        cout<<"\tStudent Textbook Purchases Report"<<endl;
        cout<<"********************************************"<<endl;
        cout<<"Student"<<"\tBook"<<"\tBook"<<"\tTax"<<"\tBook"<<endl;
        cout<<"Id"<<"\tCode"<<"\tCost"<<"\tAmount"<<"\tSubtotal"<<endl;
        cout<<"--------------------------------------------"<<endl;
        cout<<student_id<<setw(5)<<book_code<<setw(8)<<"$"<<book_cost<<
        setw(3)<<"$"<<tax_amount<<setw(4)<<"$"<<book_subtotal<<endl;
        cout<<endl;
        cout<<"Total number of books purchased:"<<setw(8)<<number_books<<endl;
        cout<<"Total books cost including tax:"<<setw(9)<<"$"<<total_book_cost<<endl;
        cout<<"Please enter your Student ID, then press enter."<<endl;
        cin>>student_id;
    }
    grand_total += total_book_cost;
    total_books_sold += number_books;
    cout<<"**************************************************"<<endl;
    cout<<"Grand Totals:"<<endl;
    cout<<"Total number of students who purchased books:"<<endl;
    cout<<"Total number of books sold:"<<endl;
    cout<<"Total cost of all books and taxes:"<<setw(9)<<"$"<<grand_total<<endl;

    //Can put grand totals here

    system("Pause");
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:29:36+00:00Added an answer on June 14, 2026 at 2:29 am

    You could use the loop as this:

    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    int main ()
    {
    
        //Set Decimal to two places.
        cout << fixed << showpoint;
        cout << setprecision(2);
    
    
        int total_books_sold = 0;
        double grand_total = 0.0;
    
        const int SENTINEL = -9999;
        int     student_id = SENTINEL;
        //Input Data
        cout<<"Please enter your Student ID, then press enter."<<endl;
        cin>>student_id;
    
        while (student_id != SENTINEL){
    
            double  total_book_cost = 0.0;
            int     number_books = 0;
            char    book_code = '\0';
            while (true) 
            {
                cout<<"Please enter your Book Code, then press enter."<<endl;
                cin>>book_code;
    
                if (book_code == 'x')
                    break;
    
                float   book_cost;
                cout<<"Please enter the cost of the book, then press enter."<<endl;
                cout<<"$"; cin>>book_cost;
    
                const double TAX = .07;
                double tax_amount = book_cost * TAX;
                double book_subtotal = book_cost + tax_amount;
    
                total_book_cost += book_subtotal; 
                number_books++;
    
                cout<<"\tStudent Textbook Purchases Report"<<endl;
                cout<<"********************************************"<<endl;
                cout<<"Student"<<"\tBook"<<"\tBook"<<"\tTax"<<"\tBook"<<endl;
                cout<<"Id"<<"\tCode"<<"\tCost"<<"\tAmount"<<"\tSubtotal"<<endl;
                cout<<"--------------------------------------------"<<endl;
                cout<<student_id<<setw(5)<<book_code<<setw(8)<<"$"<<book_cost<<
                    setw(3)<<"$"<<tax_amount<<setw(4)<<"$"<<book_subtotal<<endl;
                cout<<endl;
    
            };
    
    
            grand_total += total_book_cost;
            total_books_sold += number_books;
    
            cout<<"Total number of books purchased:"<<setw(8)<<number_books<<endl;
            cout<<"Total books cost including tax:"<<setw(9)<<"$"<<total_book_cost<<endl;
            cout<<"Please enter your Student ID, then press enter."<<endl;
            cin>>student_id;
        }
    
    
        cout<<"**************************************************"<<endl;
        cout<<"Grand Totals:"<<endl;
        cout<<"Total number of students who purchased books:"<<endl;
        cout<<"Total number of books sold:"<<endl;
        cout<<"Total cost of all books and taxes:"<<setw(9)<<"$"<<grand_total<<endl;
    
        //Can put grand totals here
    
        system("Pause");
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having this issue: I program a lot in several programming languages. I need
I'm having the same troubles with my program again. The issue this time is
having trouble coming up with search parameters for this issue, so I can't find
I'm having this rather strange issue - upon a button click, the program initializes
After having this issue on our websites over secure SSL connections for Office file
We are having this issue with our production servers (apache-tomcat-7.0.6), which is running a
I'm having this issue since offline_access has been deprecated and migration enabled. I'm getting
I'm having this issue where i use nth-child(odd) to color a table. In IE9
I am having this issue where Arabic letters are shown disjoint in any component
i'm having this issue, in ASP.NET MVC 2 where I'm adding a drop down

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.