Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 31st, 2008, 11:19 AM   #1
gmann145
Newbie
 
Join Date: Jan 2008
Posts: 7
Rep Power: 0 gmann145 is on a distinguished road
Exclamation 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
c++ Syntax (Toggle Plain Text)
  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

Last edited by Ancient Dragon; Jan 31st, 2008 at 6:50 PM. Reason: add code tags
gmann145 is offline   Reply With Quote
Old Jan 31st, 2008, 11:35 AM   #2
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Re: some help

is it not compiling?
the cin << r; should be cin>>r and /n should be \n
OpenLoop is offline   Reply With Quote
Old Jan 31st, 2008, 6:19 PM   #3
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 630
Rep Power: 4 Jessehk is on a distinguished road
Re: some help

http://www.programmingforums.org/thread14686.html
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Feb 1st, 2008, 3:21 PM   #4
pcbrainbuster
Programmer
 
Join Date: Dec 2007
Posts: 93
Rep Power: 1 pcbrainbuster is on a distinguished road
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?
pcbrainbuster is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:56 PM.

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