Thread: C++ program jumps for noobie

  1. #1
    Registered User bandito9111's Avatar
    Join Date
    Feb 2003
    Posts
    4

    Question C++ program jumps for noobie

    I am a noobie c++ programmer and have a Question on how to
    complete this program

    I want to be able to input a or v and then be able to jump to the area to input and calculate my result and display
    I tried goto(i know dont laugh)
    and tried bool but it didnt work

    someone help me


    #include<iostream>


    int main()

    {

    int area, volume, height, width, length;

    std::cout<<"\nDo you wish to calculate Area or volume?(A/V)";

    char av;

    std::cin>>av;


    { //input and calculate area
    std::cout<<"\ninput width:";
    std::cin>>width;
    std::cout<<"\ninput length:";
    std::cin>>length;
    area=length*width;
    std::cout<<"area is:";
    std::cout<<area;
    }

    { //input and calculate volume
    std::cout<<"\ninput width:";
    std::cin>>width;
    std::cout<<"\ninput height:";
    std::cin>>height;
    std::cout<<"\ninput length:";
    std::cin>>length;
    volume=height*width*length;
    std::cout<<"\nvolume is:";
    std::cout<<volume;
    }
    return 0;

    }

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    first use code tags.

    as for the problem, just use if statements.
    Code:
    if(av == 'a') {
       //area calculations
    } else {
       //volume calculations
    }
    and for goto, not recommended. it tends to be sloppy code.

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Try using IF statements:
    Code:
    if (av == 'a')
    {
         // Calculate Area....
    }
    
    else if (av == 'v')
    {
         // Calculate Volume....
    }
    ~ Paul

    Edit: Oops, someone beat me too it

  4. #4
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    wow a programmer that doesnt know control the flow of the program with if's....who teaches this...they teach you goto before they teach you if's...tsk..tsk
    nextus, the samurai warrior

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM