C++ Homework Assistance...

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2007
Posts: 3
Reputation: bmgee13 is an unknown quantity at this point 
Solved Threads: 0
bmgee13 bmgee13 is offline Offline
Newbie Poster

C++ Homework Assistance...

 
0
  #1
Apr 21st, 2007
I am new to C++ and programming in general, and am working on an upcoming homework assignment. I have run into several problems and would greatly appreciate assistance. The assignment is to write a code to determine area and volume in C++, using a While Loop. I am stuck with the while statement, I am not sure how to state when I want it to stop. Below is what I have so far.
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int area (int l, int w); // function prototype
  5.  
  6. int volume (int l, int w, int d); // function prototype
  7.  
  8. int main (int argc, char* argv[]) {
  9.  
  10. int length, width, depth; // parameters for the areas and volumes
  11.  
  12. int result; //result is output
  13.  
  14. cout << endl;
  15.  
  16. // read in the values of length, width, and depth
  17.  
  18. While (?)
  19. {
  20. cout << "If you want the result of the calculation to be an area,";
  21. cout << endl;
  22.  
  23. cout << "place a 0 in the depth parameter ";
  24. cout << endl << endl;
  25.  
  26. cout << "Enter a length (postive integer): ";
  27. cin >> length;
  28.  
  29. cout << "Enter a width (postive integer): ";
  30. cin >> width;
  31.  
  32. cout << "Enter a depth (postive integer): ";
  33. cin >> depth;
  34.  
  35. cout << endl;
  36.  
  37. if (depth == 0) {
  38. result = area (length, width);
  39. cout << "With a length of " << length;
  40. cout << " and a width of " << width;
  41. cout << " the area is " << result << endl;
  42. } else {
  43. result = volume (length, width, depth);
  44. cout << "With a length of " << length;
  45. cout << " a width of " << width;
  46. cout << " and a depth of " << depth;
  47. cout << " the volume is " << result << endl;
  48.  
  49. } // end if
  50.  
  51. } // end loop
  52. return 0;
  53.  
  54. } // end main function
  55.  
  56. int area (int l, int w) {
  57.  
  58. int result;
  59. result=area(l,w);
  60. return result;
  61.  
  62. } // end area function
  63.  
  64. int volume (int l, int w, int d) {
  65.  
  66. int result;
  67. result=volume(l,w,d);
  68. return result;
  69.  
  70. } // end volume function
Thank you,
bmgee13
Last edited by WaltP; Apr 22nd, 2007 at 11:11 pm. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,273
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 543
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: C++ Homework Assistance...

 
0
  #2
Apr 21st, 2007
Isnt it meant to be like:

While(car = red)

or similar?
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: C++ Homework Assistance...

 
0
  #3
Apr 21st, 2007
>I am stuck with the while statement, I am not sure how to state when I want it to stop.

Usually you tell the user to enter a negative number to quit when dealing with numbers (assuming of course, that you don't need negative numbers from the input). So the condition would be something like
  1. while (input >= 0)

The only problem is that you usually ask the user to enter a negative number at the first input statement at the prompt. So then you must ask the user for the dimensions of the box before the program will exit.

You can always break out of the loop if you find that the number is negative, which is probably the easiest for you (for now).

>Isnt it meant to be like: While(car = red)

That would be wrong, because = is an assignment operator. You'd be assigning car to red, which would be rather pointless, and quite likely you'd enter an infinite loop (if red never changed).
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 3
Reputation: bmgee13 is an unknown quantity at this point 
Solved Threads: 0
bmgee13 bmgee13 is offline Offline
Newbie Poster

Re: C++ Homework Assistance...

 
0
  #4
Apr 23rd, 2007
Thank you for your assistance, I do appreciate it. Although I am still unclear on the while statement, I have now used
While(result !=0). However, I am now receiving the error message
error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup I tried to look up this error message in the MS Help section, but am not receiving as much information as I would have hoped for.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: C++ Homework Assistance...

 
0
  #5
Apr 23rd, 2007
It's got something to do with Microsoft wanting t_main with their compiler, although I don't really know much about it.

I'd research it a little bit more, except I want to watch the hockey game. Sorry
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 3
Reputation: bmgee13 is an unknown quantity at this point 
Solved Threads: 0
bmgee13 bmgee13 is offline Offline
Newbie Poster

Re: C++ Homework Assistance...

 
0
  #6
Apr 23rd, 2007
Thank you, joeprogrammer. I added the 't' to _main and it seems to have fixed that problem. I will need to research it a bit more to fully understand it though. Enjoy the game!
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,651
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: C++ Homework Assistance...

 
0
  #7
Apr 24th, 2007
Originally Posted by bmgee13 View Post
Thank you for your assistance, I do appreciate it. Although I am still unclear on the while statement, I have now used
While(result !=0). However, I am now receiving the error message
error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup I tried to look up this error message in the MS Help section, but am not receiving as much information as I would have hoped for.
Its not a problem with the code but with your project configuration. The most common reason you get this errror is when you don't create a console project.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 1754 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC