All pastes #768114 Raw Edit

Basic Calculator

public cpp v1 · immutable
·published 2007-11-10 09:26 UTC
rendered paste body
#include <iostream>#include <iomanip>#include <conio.h>#include <fstream>int addition();int substract();int multiplication();int division();int info();using namespace std;int main(){            int a;      system("cls");      cout << "List: " << endl;      cout << "1: Addition" << endl << "2: Substraction" << endl << "3: Multiplication" << endl << "4: Division" << endl << "5: Info" << endl << "6: Exit" << endl;      cout << "Chose what to do: ";      cin >> a;      switch(a)      {      case 1:           addition();           break;                 case 2:           substract();           break;                 case 3:           multiplication();           break;                 case 4:          division();           break;            case 5:           info();           break;      case 6:           system("pause");           break;                 default:             main();             break;      }       }int addition(){                int a, b;                                       cout << setw(12) << "Addition" << endl;     cout << "First number ";     cin >> a;     cout << "Second number ";     cin >> b;     cout << a << " + " << b << " = " << a+b << endl;  ofstream myfile;  myfile.open ("Calculator.txt",ios::app);  myfile << a << " + " << b << "= " << a+b << "\n";  myfile.close();     cout << endl;     cout << "Press any key to go back to the menu.";     getch();     main();                }   int substract(){    int a, b;         cout << setw(4) << "Substraction" << endl;    cout << "First number ";    cin >> a;    cout << "Second number ";    cin >> b;    cout << a << " - " << b << " = " << a-b << endl;      ofstream myfile;  myfile.open ("Calculator.txt",ios::app);  myfile << a << " - " << b << "= " << a-b << "\n";  myfile.close();        cout << endl;    cout << "Press any key to go back to the menu.";    getch();    main();}int multiplication(){        int a, b;        cout << setw(4) << "Multiplication" << endl;    cout << "First number ";    cin >> a;    cout << "Second number ";    cin >> b;    cout << a << " * " << b << " = " << a*b << endl;  ofstream myfile;  myfile.open ("Calculator.txt",ios::app);  myfile << a << " * " << b << "= " << a*b << "\n";  myfile.close();        cout << endl;    cout << "Press any key to go back to the menu.";    getch();    main();    }int division(){    int a, b;        cout << setw(4) << "Division" << endl;    cout << "First number ";    cin >> a;    cout << "Second number ";    cin >> b;    cout << a << " / " << b << " = " << a/b << endl;      ofstream myfile;  myfile.open ("Calculator.txt",ios::app);  myfile << a << " / " << b << "= " << a/b << "\n";  myfile.close();        cout << endl;    cout << "Press any key to go back to the menu.";    getch();    main();        }int info(){    cout << "At this point the program has a bug when it comes to letters. \nIt has a tendensy to start loop the program or make different calculations\non it's own. \n\nSecond; this program don't have to many options to use several different \nnumbers or operators at once, so instead all your data is saved in a text \ndocument in the same folder as your exe-file is." << endl << endl;    cout << "Press any key to go back to the menu.";    getch();    main();}