### Program that calculates discounts.

So my midterm exam for programming is done. My program didn't run. Tried rewriting it once I got home. I am still getting an error that the program could not be run. Also, we weren't allowed to use the internet. So I didn't know how to calculate for the discounted rate. Code will be posted below. If they're are any suggestions in making this code simpler, I would really appreciate it.

I am using Microsoft Visual Studio 2010.

Given problem:

ABC Hotel offers 5-10% discounts depending on how much money has the user spent. If item purchase is lesser than 1000php (1USD is 43.19PHP) 5% discount is availed. Greater than 1000php then 10% discount is availed. Total price and discounted price should be displayed.

I posted this in the forum not to cheat, cause the exam is long done. I just wanna learn more about programming.

#include<iostream>
using namespace std;

main()
{
float a,b,c,d,e,f,g,h,i,j,total,discounted_price;
cout<<"Please input price of first 1st item: ";
cin>>a;
cout<<"Please input price of first 2nd item: ";
cin>>b;
cout<<"Please input price of first 3rd item: ";
cin>>c;
cout<<"Please input price of first 4th item: ";
cin>>d;
cout<<"Please input price of first 5th item: ";
cin>>e;
cout<<"Please input price of first 6th item: ";
cin>>f;
cout<<"Please input price of first 7th item: ";
cin>>g;
cout<<"Please input price of first 8th item: ";
cin>>h;
cout<<"Please input price of first 9th item: ";
cin>>i;
cout<<"Please input price of first 10th item: ";
cin>>j;
total=a+b+c+d+e+f+g+h+i+j;
cout<<"The total non discounted price is: "<<total;

if (total>=1000);
{
discounted_price=(0.10*total+total);
cout<<"10% discount has been availed, your total bill is: "<<discounted_price;
}

else

discounted_price=(0.05*total+total);
cout<<"5% discount has been availed, your total bill is: "<<discounted_price;

system("pause>0");
}
Last edited on
Please please please use code tags, which you can get from the <> button next to the editing box!

Line 4: main() needs to be declared as an int because C++ doesn't support default-int.

Line 30: Stray semicolon.
Lines 32 - 33: Shouldn't these be in brackets?

This whole program could be made simpler with an array.

-Albatross
Topic archived. No new replies allowed.