# wrote a program; please review/comment

• 05-22-2003
spirited
Will this program run?
Any suggestions?

Problem: write a c++ program that prompts the user for a cost per item, number of items purchased, and a discount rate. The program should then calculate and print the total cost, tax due, and amount due.

My program and algorithm:
//prompt the user for a cost per item
//prompt the user for number of items purchased
//prompt the user for a discount rate
//calculate the total cost, tax due, and amount due.
//print the total cost, tax due and amount due
#include <iostream.h>
int main()
{
const float salestax = 0.06;
float numberitems, costperitem, discountrate, totalcost, taxdue, amountdue, taxrate, newtotal;

totalcost = numbitems * costperitem;
newtotal = totalcost - (discountrate * totalcost)
taxdue = newtotal * taxrate
amountdue = newtotal + taxdue

cout<<"enter cost per item";
cin>> costperitem
cout<<"enter number of items";
cin>> numberitems

cout<<"enter discount rate";
cin>> discountrate
cout<< “Your amount due is”<< amountdue
return 0;
}
• 05-22-2003
Rez
Nope, it will not run as you would have expected :) The flow is incorrect and you forgot some line treminators. Here, I rearranged it for you:
Code:

```#include <iostream.h> int main() {   const float salestax = 0.06;   float numberitems, costperitem, discountrate, totalcost;   float taxdue, amountdue, taxrate, newtotal;   cout<<"enter cost per item";   cin>> costperitem;   cout<<"enter number of items";   cin>> numberitems;   cout<<"enter discount rate";   cin>> discountrate;   totalcost = numbitems * costperitem;   newtotal = totalcost - (discountrate * totalcost);   /*You forgot to compute the taxrate*/;   taxdue = newtotal * taxrate;   amountdue = newtotal + taxdue;   cout<< "Your amount due is"<< amountdue;   return 0; }```
• 05-22-2003
XSquared
Rez, you put a semicolon after your comment about leaving out the calculation of sales tax, and also, don't use <iostream.h>. Use <iostream> and using namespace std;.
• 05-22-2003
Rez
Oops hehe sorry. :) But even if it has a semicolon, it won't affect the execution anyway.
• 05-22-2003
XSquared
I know, I just thought I'd point it out.