944,161 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1567
  • C++ RSS
Jun 25th, 2006
0

Help, Won't Run

Expand Post »
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! :-)

C++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ace01000 is offline Offline
2 posts
since Jun 2006
Jun 25th, 2006
0

Re: Help, Won't Run

>> 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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Dynamic Array of Structures, Loop problem!
Next Thread in C++ Forum Timeline: Modularity





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC