i am writing a code for class and have gotten everything else to work with my compiler except my else statements.
I keep getting the "expected primary expression before 'else'" and the "expected ( before 'else'" as well
the first functions of my code is as follows:
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
/*
a=volume
b=surface area
r=radius
*/
double x,r,a,b,c,h,l,w;
(putting a resp return command here after i finish this problem)
cout<< "What shape would you like?"<<endl;
cout<< "1) Sphere"<< endl;
cout<< "2) Cone"<< endl;
cout<< "3) Rectangular Prism"<< endl;
cout<< "4) Cylinder"<< endl;
cin>>x;
if (x==1); // Sphere
{
cout<<"Radius=";
cin>>r;
while(cin.fail()<'0');
{
cout<<"ERROR! VALUE MUST BE GREATER THAN 0"<<endl;
cin.clear();
cin.ignore(256,'\n');
cout<< "Radius=";
cin>>r;
};
a=((4.0/3.0)*M_PI)*pow(r,3.0);
b=(4*M_PI)*pow(r,2.0);
cout<<"Volume="<<a<< endl;
cout<<"Surface Area="<<b<<endl;
}
else if (x==2); // Cone
{
(Yes i am a next liner)
The rest of the program is very similar to this part with the 'if' statement followed by command code followed by and else statement and repeat through all 4 shapes
if you would like to see the next section of the code let me know and i will post it in here.
any help would be great, thx
Dave