unknown problem!

This is a discussion on unknown problem! within the C++ Programming forums, part of the General Programming Boards category; I am writing a program to calculate the area of shapes i've hit a problem everytime i run the program ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    2

    unknown problem!

    I am writing a program to calculate the area of shapes i've hit a problem everytime i run the program and input my choice it prints the start again-

    Code:
    #include <iostream>
    using namespace std;
    
    int main(){
        int choice, w, l;
        do{
           cout << "Find the Area\n";
           cout << "Please enter number of choice(q for quit): \n";
           cout << "1. Square\n";
           cout << "2. Rectangle\n";
           cout << "3. Triangle\n";
           cout << "4. Circle\n";
           cout << "5. Cube\n";
           cin >> choice;
           } while ( choice < '1' || choice > '5' && choice != 'q' );
           
           if (choice == 'q') exit(1);
           
           switch (choice){
                  case '1':
                       cout << "\nEnter the width: ";
                       cin >> w;
                       cout << "\nArea is: " << w*w << "cm2";
                  case '2':
                       cout << "\nEnter the width: ";
                       cin >> w;
                       cout << "\nEnter the length: ";
                       cin >> l;
                       cout << "\nArea is: " << w*l << "cm2";
                  case '3':
                       cout << "\nEnter the width: ";
                       cin >> w;
                       cout << "\nEnter the height: ";
                       cin >> l;
                       cout << "\nArea is: " << 2/(w*l) << "cm2";
                  case '4':
                       cout << "\nEnter the radius: ";
                       cin >> w;
                       cout << "\nArea is: " << 3.14*(w*w) << "cm2";
                  case '5':
                       cout << "/nEnter the height: ";
                       cin >> l;
                       cout << "/nArea is: " << l*l*l << "cm3";
                       }
                  return 0;
                  }
    Thanks for any help, it is much appreciated.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,269
    You probably want choice to be a char instead of an int.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You are mixing up \ and / some of the time. Other than that, when you press 5, what do you do next? Hit enter. It's in the FAQ.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    2
    problem fixed thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  3. Unknown problem
    By Mindphuck in forum C Programming
    Replies: 3
    Last Post: 04-08-2006, 03:35 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Unknown problem
    By pink_langouste in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 12:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21