-
Help?
WHy wont the following work??
Code:
#include <iostream.h>
#include <conio.h>
int main()
{
double radius;
const double pi=3.14;
char calc;
cout<<"This program can calculate Surface area and Volume for a sphere. Type in V for Volume calculation or S for Surface area."<<endl;
cin>>calc;
if(calc=="V")
{
cout<<"What is the radius of the sphere?"<<endl;
cin>>radius;
cout<<"The Volume of the sphere is: "<<(4*pi*(radius*radius)/3)<<endl;
}
if(calc=="v")
{
cout<<"What is the radius of the sphere?"<<endl;
cin>>radius;
cout<<"The Volume of the sphere is: "<<(4*pi*(radius*radius*radius)/3)<<endl;
}
if(calc=="S")
{
cout<<"What is the radius of the sphere?"<<endl;
cin>>radius;
cout<<"The Surface area of the sphere is: "<<(4*pi*(radius*radius))<<endl;
}
if(calc=="s")
{
cout<<"What is the radius of the sphere?"<<endl;
cin>>radius;
cout<<"The Surface area of the sphere is: "<<(4*pi*(radius*radius))<<endl;
}
getch();
getch();
return 0;
}
Id appreciate the help
-
uh ?
-
1 Attachment(s)
Ahh
yes of course... that could be important :D
Well the compiler wont compile it
this is what happens
-
i am not sure if this will solve it but try make a varable to hold the volume and stuff like this:
int * pVolume = 0;//pointer
*pVolume= (4*pi*(radius*radius)
something like that!
-
how would that help though
the problem seems to be in the IF statement
-
Here is the fixed version of your code. You must use single quotes rather than double quotes to indicate characters.
PHP Code:
#include <iostream.h>
#include <conio.h>
int main()
{
double radius;
const double pi=3.14;
char calc;
cout<<"This program can calculate Surface area and Volume for a sphere. Type in V for Volume calculation or S for Surface area."<<endl;
cin>>calc;
if(calc=='V')
{
cout<<"What is the radius of the sphere?"<<endl;
cin>>radius;
cout<<"The Volume of the sphere is: "<<(4*pi*(radius*radius)/3)<<endl;
}
if(calc=='v')
{
cout<<"What is the radius of the sphere?"<<endl;
cin>>radius;
cout<<"The Volume of the sphere is: "<<(4*pi*(radius*radius*radius)/3)<<endl;
}
if(calc=='S')
{
cout<<"What is the radius of the sphere?"<<endl;
cin>>radius;
cout<<"The Surface area of the sphere is: "<<(4*pi*(radius*radius))<<endl;
}
if(calc=='s')
{
cout<<"What is the radius of the sphere?"<<endl;
cin>>radius;
cout<<"The Surface area of the sphere is: "<<(4*pi*(radius*radius))<<endl;
}
getch();
getch();
return 0;
}
-
thx :D
so all i needed was to change the " to '?