help on while loop

I would like to know how i can fix my code, all i have is one error (expected unqualified-id before '{' token and it highlights line 17, is my loop correct?


#include<iostream>
#include<cmath>

using namespace std;
int main()

{
int y=1;
do
{
cout <<"Enter Type of Apple Purchased"<< endl<< "Enter [1] for premium"<< endl<< "Enter [2] for juicy"<< endl<<
"Enter [3] for snack"<< endl<< "Enter [4] for cooking"<< endl;
}while (y==1);
return 0;
}

{
int y;
int grade;
int quantity;
double premium (.40), juicy (.30), snack (.20), cooking (.10),cost1, cost2,cost3,cost4, Total, tax,subtax;

cout <<"Enter Type of Apple Purchased"<< endl<< "Enter [1] for premium"<< endl<< "Enter [2] for juicy"<< endl<<
"Enter [3] for snack"<< endl<< "Enter [4] for cooking"<< endl;
cin>> grade;
if (grade==1)
{
cout<<"Enter number of premium apples purchased" << endl;
cin>> quantity;
cost1= quantity*(.40);
cout<<"Did you buy any other grade of apple?"<< endl<< "press [1] for yes"<< endl<<"press[0] for no"<< endl;
cin>> y;
}
else if (grade == 2)
{

cout<< "Enter number of juicy apples purchased"<< endl;
cin>> quantity;
cost2=quantity*(.30);
}
else if (grade==3)
{
cout<<"Enter number of snack apples purchased"<< endl;
cin>>quantity;
cost3=quantity*(.20);
}
else if (grade==4)
{
cout<<"Enter number of cooking apples purchased"<< endl;
cin>>quantity;
cost4=quantity*(.10);
}
Total= (cost1+cost2+cost3+cost4);
tax= Total*.07;
subtax= Total+tax;
std::cout.precision(2);
std::cout.setf(std::ios::fixed);

cout << "Your total price is"<< endl<< subtax <<endl;
system("pause");
return 0;


}
closed account (1CfG1hU5)
below main(), 13 lines down, just above the "int y;" declaration. looks though you have
an unnecessary brace "{".

the do while loop looks okay at a quick glance. hope I didn't miss something. tired.

Last edited on
It has nothing to do with the loop. After main() ends it looks like you want another function, but the head is missing.

You have this
1
2
cout <<"Enter Type of Apple Purchased"<< endl<< "Enter [1] for premium"<< endl<< "Enter [2] for juicy"<< endl<<
"Enter [3] for snack"<< endl<< "Enter [4] for cooking"<< endl;
twice


Please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/
Topic archived. No new replies allowed.