Calc end and loop?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 2
Reputation: iseedeadpeople is an unknown quantity at this point 
Solved Threads: 0
iseedeadpeople iseedeadpeople is offline Offline
Newbie Poster

Calc end and loop?

 
0
  #1
Dec 11th, 2007
Ok, i used a couple C++ programming books to help me make a calc. A friend of mine suggest that i make a "Would you like to solve another problem? (Y/N)" and Y loops back and N closes the program. here is my code:
  1. #include <iostream.h>
  2.  
  3. int Add(int num1, int num2);
  4. int Subtract(int num1, int num2);
  5. int Multiply(int num1, int num2);
  6. int Divide(int num1, int num2);
  7.  
  8. // The main procedure. When the program starts, it goes here.
  9. int main(int argc, char *argv[])
  10. {
  11. int x, y; // Integers 'x' and 'y' - The two numbers to add
  12. int doNum; // Integer 'doNum' - Add, Subtract, Multiply, or Divide?
  13. int b=1; // Integer 'b' - App runs while b = 1
  14.  
  15. while(b==1)
  16. {
  17. cout<<"Please enter two numbers with a space inbetween.press enter: ";
  18. cin>>x>>y;
  19.  
  20. cout<<"Pleas press the number of what you want to do, press enter: "<<endl;
  21. cout<<"1. Add"<<endl;
  22. cout<<"2. Subtract"<<endl;
  23. cout<<"3. Multiply"<<endl;
  24. cout<<"4. Divide"<<endl;
  25. cin>>doNum;
  26.  
  27. switch (doNum)
  28. {
  29. case 1:
  30. cout<<x<<" plus "<<y<<" = "<<Add(x, y)<<endl;
  31. break;
  32. case 2:
  33. cout<<x<<" minus "<<y<<" = "<<Subtract(x, y)<<endl;
  34. break;
  35. case 3:
  36. cout<<x<<" multiplied by "<<y<<" = "<<Multiply(x, y)<<endl;
  37. break;
  38. case 4:
  39. cout<<x<<" divided by "<<y<<" = "<<Divide(x, y)<<endl;
  40. break;
  41. } //switch
  42. } //while
  43.  
  44. return 0;
  45. }
  46.  
  47. // This function adds two variables
  48. int Add(int num1, int num2)
  49. {
  50. return num1+num2;
  51. }
  52.  
  53. // This function subtracts two variables
  54. int Subtract(int num1, int num2)
  55. {
  56. return num1-num2;
  57. }
  58.  
  59. // This function multiplies two variables
  60. int Multiply(int num1, int num2)
  61. {
  62. return num1*num2;
  63. }
  64.  
  65. // This function divides the first variable by the second
  66. int Divide(int num1, int num2)
  67. {
  68. return num1/num2;
  69. }
Last edited by Ancient Dragon; Dec 11th, 2007 at 10:01 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,381
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Calc end and loop?

 
0
  #2
Dec 11th, 2007
Ok, so you want to add that feature. What is your question ?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2
Reputation: iseedeadpeople is an unknown quantity at this point 
Solved Threads: 0
iseedeadpeople iseedeadpeople is offline Offline
Newbie Poster

Re: Calc end and loop?

 
0
  #3
Dec 11th, 2007
well i've read my books and i cant quite tell where exactly i should put the command at.

Note: this is my first real program i've made besides VBS
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,381
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Calc end and loop?

 
0
  #4
Dec 11th, 2007
I would probably put that prompt between lines 41 and 42.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1
Reputation: dronzer0tihs is an unknown quantity at this point 
Solved Threads: 0
dronzer0tihs dronzer0tihs is offline Offline
Newbie Poster

Re: Calc end and loop?

 
0
  #5
Dec 12th, 2007
why not just put the whole main program inside a do while loop. then place your question before the program ends
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,381
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Calc end and loop?

 
0
  #6
Dec 12th, 2007
Originally Posted by dronzer0tihs View Post
why not just put the whole main program inside a do while loop. then place your question before the program ends
I think that's what I just said.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC