Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Calculator Problem

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 09-24-2012, 02:25 AM PM User | #1 va396053 New to the CF scene   Join Date: Sep 2012 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts Calculator Problem Assignment: Write a program, which will act as a simple four-function calculator. That is it will read a number, read an operator, read another number, then do the operation. The calculator works with integers and uses four functions: +, -, *, and /. After the first operation is completed, the program will read another operator and uses the result of the previous operation as the first value for the next operation. If the user enters a C the result is cleared and then the user starts entering a new number. If the user enters an X, the calculator is turned off. The various input values (i.e. numbers, operators, commands) will be followed by the ENTER key. Your program should prompt the user on what the user is to do. The commands C and X may be entered in place of an operator This is what I did. I am not sure whether it is right or not. Can anyone help me with this? Thanks #include using namespace std; #include void main() { bool InvalidOp; int Number1; int Number2; char op; cout << "Please enter a number and press enter: "; cin >> Number1; cout << "Please enter another number and press enter: "; cin >> Number2; cout << "Please enter a a valid operator, 'c' to clear, or 'x' to turn off and press ENTER : "; cin >> op; do { cout << "Enter an operator [+-*/ccXx]: "; cin >> Op; InvalidOp = false; switch (op) { case '+': cout << "The result is: " << Number1 + Number2 << endl; break; case '-': cout << "The result is: " << Number1 - Number2 << endl; break; case '*': cout << "The result is: " << Number1 * Number2 << endl; break; case '/': cout << "The result is: " << Number1 / Number2 << endl; break; case 'C': case 'c': break; case 'X': case 'x': cout << "Bye" << endl; exit (0); default: cout << "Invalid operator" << endl; InvalidOp = true; } } while (InvalidOp); }
 09-25-2012, 02:41 AM PM User | #2 sunfighter Senior Coder   Join Date: Jan 2011 Location: Missouri Posts: 3,269 Thanks: 23 Thanked 468 Times in 467 Posts

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 09:13 AM.