Thread: unknown problem!

  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
    28,413
    You probably want choice to be a char instead of an int.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Unknown problem
    By Mindphuck in forum C Programming
    Replies: 3
    Last Post: 04-08-2006, 02: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