help to calculate

Student Textbook Purchases Report
Last edited on
array
Last edited on
If you edit your post so it uses code tags - the <> button on the right - you might get more help.

Also post your compiler output in full, if you have any.

AM looking forward to helping out. :)
i
Last edited on
You should store your data into an array or a vector. At the moment your code loops, but you are overwriting the values with new values, so this is why it only shows the last values entered.

A while loop would be better (as hinted by the comment) - here's how to quit out of it:

1
2
3
4
5
6
7
8
9
bool Quit = false;

while(!Quit) {
    //your code here

    //user wants to quit
     Quit = true;
}


Hope all goes well.
Also you need to improve your code writing.
The code should be more clear (More understandable & improve the readability).

Several tips for you :
For example :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Declare Variables.    
int student_id;
char Book_code;
int Book_cost;
int number_days;
float Book_subtotal;
const float TAXRATE = .07;
int Totalbooks_purchased;
float Total_books_cost_including_tax;
const int SENTINEL = 0;
//Show point.
cout << fixed << showpoint;
cout << setprecision(2);
const int flag=0;
int Atax;


This may be very complex. Change it to :

1
2
3
4
5
6
7
8
9
10
11
//Declare Variables.  
const int SENTINEL = 0, flag=0;
int student_id ,Book_cost , number_days, Totalbooks_purchased;

const float TAXRATE = 0.07, Book_code;
float Book_subtotal,Total_books_cost_including_tax;

int Atax;

//Show point.
cout << fixed << showpoint;cout << setprecision(2);


And, your variable names are very long and maybe hard to remember. Next, you should add a special letter before the name of any variable for different specific variable types. This can show everyone what the type of a variable is and improve the readability.


1
2
3
4
5
6
7
8
//Declare Variables.  
const int nSENTINEL = 0, nflag=0;
int nstudent_id ,nBook_cost , nNumber_days, nTotalbooks_purchased;

const float fTAXRATE = 0.07, fBook_code;
float fBook_subtotal, fTotal_books_cost_including_tax;

int nAtax;


Here, special letters (basic & popular) :
n : Int (int nTotal)
f : float
////////////////
dw : DWORD
////////////////
lp : Pointer

Hope some of this can help.
Last edited on
@Jackson Marie

I disagree a bit, declaring variables all together on one line does not make the code easier to read IMO.

If you put them each on their own line, you have the opportunity to initialise them (not doing this is often a major source of errors), and write a comment to say what the variable means (important if it is abbreviated), or provide info about valid ranges etc.

With variable names, I like to do this:

1
2
3
const float TaxRate = 0.07;
unsigned NumDays;
unsigned NumBooks;


As you can see Words can be abbreviated a bit, use capitals for the first letter. Don't use underscores - it make the name too long.

As for type hungarian notation, there are all kinds of personal preferences which probably don't match up between different people. For example I might use i for int, and p for pointer. I have gone away from that for basic types these days - my IDE tells me all sorts of info about variables. I still use p for pointer and C for class, and m_ for member variables.

With integer types, I use the stdint header which has types described by their sign and the number of bits used like uint8_t, int32_t, uint64_t instead of unsigned char, int and unsigned long (possibly unsigned long long)

HTH
Topic archived. No new replies allowed.