Results 1 to 7 of 7

Thread: Help?

  1. #1
    Aerials
    Guest

    Question 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

  2. #2
    Lively Member slx47's Avatar
    Join Date
    Apr 2002
    Location
    US
    Posts
    127

    uh ?

    what is the problem ?

  3. #3
    Aerials
    Guest
    Ahh
    yes of course... that could be important

    Well the compiler wont compile it
    this is what happens
    Attached Images Attached Images  

  4. #4
    Lively Member slx47's Avatar
    Join Date
    Apr 2002
    Location
    US
    Posts
    127
    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!

  5. #5
    Aerials
    Guest
    how would that help though
    the problem seems to be in the IF statement

  6. #6
    Member
    Join Date
    Feb 2001
    Posts
    57
    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;


  7. #7
    Aerials
    Guest
    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
  •  



Click Here to Expand Forum to Full Width