Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   some help (http://www.programmingforums.org/showthread.php?t=15097)

gmann145 Jan 31st, 2008 12:19 PM

some help
 
hey im writting a simple code for a school assignment and for the life of me i cant figure out whats wrong with it, here it is
:

  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8. int choice;
  9. double a,r,l,w;
  10. const double z = 3.14159;
  11. const double k = .5;
  12.  
  13. cout<<"Which would you like to do?/n";
  14. cout<<"Enter 1 for area of a circle/n";
  15. cout<<"Enter 2 for area of a rectangle/n";
  16. cout<<"Enter 3 for area of a Triangle/n";
  17. cout<<"Enter 4 if you are a nancy/n";
  18. cin >> choice;
  19.  
  20. if(choice>=1 && choice<=3)
  21.     {
  22.  
  23. switch(choice)
  24.             {
  25.     case 1: cout<<"What is the radius?/n";
  26.             cin << r;
  27.             a=z*(r*r);
  28.             cout<<"The area equals " <<a;
  29.             break;
  30.     case 2:    cout<<"What are the width and legnth of the rectangle?/n";
  31.             cin>> w >> l;
  32.             a=l*w;
  33.             cout <<"The area equals " <<a;
  34.             break;
  35.     case 3:    cout<<"What are the base and height of the triagnle?/n";
  36.             cin>> l >> w;
  37.             a=l*w*k;
  38.             cout<<"The area euqals "<<a;
  39.  
  40.         case 4: break;
  41.                         }   
  42.     }
  43.  
  44. else if (x!=4)
  45.         {
  46.     cout<<"That's not a choice, re-run the program";
  47.         }
  48.  
  49.  
  50.  
  51. system("pause");
  52. return 0;
  53. }


if anyone could help me it would be much appreciated

OpenLoop Jan 31st, 2008 12:35 PM

Re: some help
 
is it not compiling?
the cin << r; should be cin>>r and /n should be \n

Jessehk Jan 31st, 2008 7:19 PM

Re: some help
 
http://www.programmingforums.org/thread14686.html

pcbrainbuster Feb 1st, 2008 4:21 PM

Re: some help
 
Quote: case 4: break;
The code will never evaluate to that, due to - "if(choice>=1 && choice<=3)" - only the cases 1, 2 and 3 will...

Quote: else if (x!=4)
What is x?

Quote: #include <iomanip>
What function/macro/etc are you using from this header?


All times are GMT -5. The time now is 3:58 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC