Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board Calc Code For BLaCkLiSt3D Download Source Code
Author Details Code Information
funkyjunky ( Ed George )

Pinned 2 Codes
Posted 1 Coding Articles

Send A Message
View Coders Profile
Language C++
Expires Never
Length 2,264 Characters (86 Lines)
Password no password
Description

Im sorry if this pasted badly!
I hope you can see what you can improve on!

good Luck
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. void calcTool();
  9. void dispOptions();
  10.  
  11. int main(){
  12.  
  13.      int ui(1);
  14.  
  15.      while (ui){
  16.  
  17.         dispOptions();
  18.         cin>>ui;
  19.         cin.ignore();
  20.  
  21.         switch (ui){
  22.  
  23.             case 1:
  24.                 calcTool();
  25.                  break;
  26.             default:
  27.                  break;
  28.  
  29.  
  30.         } //End switch
  31.  
  32.      }
  33.  
  34.  
  35.  
  36.      cin.get();
  37.      return 0;
  38.  
  39. }
  40.  
  41. void dispOptions(){
  42.       cout << "-------------MAIN-MENU-------------"<<endl;
  43.           cout<<"Enter 1 for Calculator"<<endl;
  44.                      cout<<"Enter another number to exit"<<endl;
  45.         cout << "-----------------------------------"<<endl;
  46.        cout <<"Choice: ";
  47. }
  48.  
  49. void calcTool(){
  50.  
  51.                          double left, right; // Operands
  52.                                                             char oper; // Operator
  53.                                                             double result; // Resulting value
  54.                                                   cout << "---------------------------"<<endl;
  55.                                                   cout<<"Welcome to Calculator"<<endl;
  56.                                                   cout << "---------------------------"<<endl;
  57.                                                   cout<<"Only + - * and / are valid operators"<<endl;
  58.                                                   cout << "---------------------------"<<endl;
  59.                                                   cout << "Please note that if any value is (example) 6.02e23"<<endl;
  60.                                                   cout << "It simply means 6.02 x 10^23"<<endl;
  61.                                                   cout << "If the value is (example) 1.6e-19"<<endl;
  62.                                                   cout << "It simply means 1.6 x 10^-19"<<endl;
  63.                                                   cout << "---------------------------"<<endl;
  64.                                                   cout<<"Please enter your sum"<<endl;
  65.                                                             while (cin >> left >> oper >> right) {
  66.                                                   switch (oper) {
  67.                                                             case '+': result = left + right;
  68.                        break;
  69.                                                             case '-': result = left - right;
  70.                        break;
  71.                                                             case '*': result = left * right;
  72.                        break;
  73.                                                             case '/':
  74.                                                             if(right == 0){
  75.                                                             cout << "Cannot Divide By Zero"<<endl;
  76.                                                             result = 0;
  77.                                                             }else{
  78.                                                             result = left / right;}
  79.                        break;
  80.                                                             default : cout << "Bad operator '" << oper << "'" << endl;
  81.                                                             continue; // Start next loop iteration.
  82.          }
  83.          cout << result << endl << endl;
  84.  
  85.   }
  86. }
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
Page 1 of 1
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved