Help, Won't Run

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

Join Date: Jun 2006
Posts: 2
Reputation: Ace01000 is an unknown quantity at this point 
Solved Threads: 0
Ace01000 Ace01000 is offline Offline
Newbie Poster

Help, Won't Run

 
0
  #1
Jun 25th, 2006
This is my second attempt at a calculator, but my first at switch statements. I try to compile this, but i get a bulk of errors that make no sense to me, they all look rather similar, here is an example of the error: error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Elem> &' from 'std::istream'. I have a feeling that I may have messed up in many, many places in this code, so I can understand if it is to time consuming to help me. All help is greatly appriciated! :-)

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8. int x, y, z;
  9. char math_operator, exit_app;
  10. int startover(char& exit_app);
  11. int calculation(int x, int y, int& z, char math_operator);
  12.  
  13.  
  14. cout << "(x ? y) - Please your first number followed by a space, then a legal math operator, followed by a space, then your second number. - (x ? y): ";
  15. cin >> x >> math_operator >> y;
  16.  
  17. while ((math_operator = '/') && (y == 0))
  18. {
  19. cout << "Error: Cannot divide by zero." << endl;
  20. cout << "Please re enter a legal math operator ( Supported: Addition(+), Subtraction(-), Multiplication(*), Divide(/) ): ";
  21. cin << math_operator;
  22. }
  23.  
  24. while ((math_operator != '+') (math_operator != '-') (math_operator != '*') (math_operator != '/'))
  25. {
  26. cout << "You have not entered a supported math operator." << endl;
  27. cout << "Please enter a legal math operator: ";
  28. cin >> math_operator;
  29. }
  30.  
  31. calculation(x, y, z, math_operator);
  32.  
  33. cout << x << " " << math_operator << " " << y << " = " << z << endl;
  34.  
  35. startover(exit_app);
  36.  
  37.  
  38. }
  39.  
  40.  
  41.  
  42. int calculation(int x, int y, int& z, char math_operator)
  43. {
  44.  
  45. switch (math_operator)
  46. {
  47. case '+': z = x + y; break;
  48. case '-': z = x - y; break;
  49. case '*': z = x * y; break;
  50. case '/': z = x / y; break;
  51. }
  52.  
  53. return z;
  54.  
  55. }
  56.  
  57. int startover(char& exit_app)
  58. {
  59.  
  60. cout << "Thank you for using my program!" << endl;
  61. cout << "Would you like to start over? ( s = start over, q = quit ): ";
  62. cin >> exit_app;
  63.  
  64. switch (exit_app)
  65. {
  66.  
  67. case 's': main()
  68. case 'q': cout << "Have a nice day!" << endl;
  69.  
  70. }
  71.  
  72. cin.get()
  73.  
  74. }
Last edited by Dave Sinkula; Jun 25th, 2006 at 9:52 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,629
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: 1496
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Help, Won't Run

 
0
  #2
Jun 25th, 2006
>> cin << math_operator;

you used the output operator, not input. You meant this:
cin >> math_operator;

>> case 's': main()
Not allowed to call function main() in either c or c++. You will have to think of a different way to restart the program.
Last edited by Ancient Dragon; Jun 25th, 2006 at 8:44 pm.
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
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC