|
-
May 8th, 2002, 05:19 PM
#1
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
-
May 8th, 2002, 05:26 PM
#2
Lively Member
-
May 8th, 2002, 05:33 PM
#3
-
May 8th, 2002, 05:52 PM
#4
Lively Member
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!
-
May 8th, 2002, 06:11 PM
#5
how would that help though
the problem seems to be in the IF statement
-
May 8th, 2002, 07:54 PM
#6
Member
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;
}
-
May 11th, 2002, 09:42 AM
#7
thx 
so all i needed was to change the " to '?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|