| | |
Help, Won't Run
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2006
Posts: 2
Reputation:
Solved Threads: 0
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)
#include <iostream> using namespace std; int main() { int x, y, z; char math_operator, exit_app; int startover(char& exit_app); int calculation(int x, int y, int& z, char math_operator); 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): "; cin >> x >> math_operator >> y; while ((math_operator = '/') && (y == 0)) { cout << "Error: Cannot divide by zero." << endl; cout << "Please re enter a legal math operator ( Supported: Addition(+), Subtraction(-), Multiplication(*), Divide(/) ): "; cin << math_operator; } while ((math_operator != '+') (math_operator != '-') (math_operator != '*') (math_operator != '/')) { cout << "You have not entered a supported math operator." << endl; cout << "Please enter a legal math operator: "; cin >> math_operator; } calculation(x, y, z, math_operator); cout << x << " " << math_operator << " " << y << " = " << z << endl; startover(exit_app); } int calculation(int x, int y, int& z, char math_operator) { switch (math_operator) { case '+': z = x + y; break; case '-': z = x - y; break; case '*': z = x * y; break; case '/': z = x / y; break; } return z; } int startover(char& exit_app) { cout << "Thank you for using my program!" << endl; cout << "Would you like to start over? ( s = start over, q = quit ): "; cin >> exit_app; switch (exit_app) { case 's': main() case 'q': cout << "Have a nice day!" << endl; } cin.get() }
Last edited by Dave Sinkula; Jun 25th, 2006 at 9:52 pm.
>> 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.
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.
![]() |
Similar Threads
- Can't run JSP in Browser (JSP)
- Computer freezes when dial up is run (Windows NT / 2000 / XP)
- Hello, my name is Mike and I currently run and own mlbcenter.com. Our Head Tech Supor (Community Introductions)
- Unwanted file in run menu (Windows NT / 2000 / XP)
- can't run max payne 2 (Windows NT / 2000 / XP)
- Can't run JSP in Browser (Web Browsers)
- Run-Time Error..? (Windows NT / 2000 / XP)
- Run WinXP in Linux? (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: Dynamic Array of Structures, Loop problem!
- Next Thread: Modularity
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






