| | |
Calc end and loop?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 2
Reputation:
Solved Threads: 0
Ok, i used a couple C++ programming books to help me make a calc. A friend of mine suggest that i make a "Would you like to solve another problem? (Y/N)" and Y loops back and N closes the program. here is my code:
c++ Syntax (Toggle Plain Text)
#include <iostream.h> int Add(int num1, int num2); int Subtract(int num1, int num2); int Multiply(int num1, int num2); int Divide(int num1, int num2); // The main procedure. When the program starts, it goes here. int main(int argc, char *argv[]) { int x, y; // Integers 'x' and 'y' - The two numbers to add int doNum; // Integer 'doNum' - Add, Subtract, Multiply, or Divide? int b=1; // Integer 'b' - App runs while b = 1 while(b==1) { cout<<"Please enter two numbers with a space inbetween.press enter: "; cin>>x>>y; cout<<"Pleas press the number of what you want to do, press enter: "<<endl; cout<<"1. Add"<<endl; cout<<"2. Subtract"<<endl; cout<<"3. Multiply"<<endl; cout<<"4. Divide"<<endl; cin>>doNum; switch (doNum) { case 1: cout<<x<<" plus "<<y<<" = "<<Add(x, y)<<endl; break; case 2: cout<<x<<" minus "<<y<<" = "<<Subtract(x, y)<<endl; break; case 3: cout<<x<<" multiplied by "<<y<<" = "<<Multiply(x, y)<<endl; break; case 4: cout<<x<<" divided by "<<y<<" = "<<Divide(x, y)<<endl; break; } //switch } //while return 0; } // This function adds two variables int Add(int num1, int num2) { return num1+num2; } // This function subtracts two variables int Subtract(int num1, int num2) { return num1-num2; } // This function multiplies two variables int Multiply(int num1, int num2) { return num1*num2; } // This function divides the first variable by the second int Divide(int num1, int num2) { return num1/num2; }
Last edited by Ancient Dragon; Dec 11th, 2007 at 10:01 pm. Reason: add code tags
![]() |
Similar Threads
- Couple of errors in my code (Java)
- Pass by reference in Function call results not correct (C++)
- Issues with double linked list (C++)
- simple cash register (pos) problem - please help!! (VB.NET)
- Getting errors while compiling (Java)
- arrays and functions (C++)
- Calculator program returning random values (Assembly)
- Help please with incorrect gas mileage calculation (C)
- Simple C++ program terminate prematurely (C++)
Other Threads in the C++ Forum
- Previous Thread: String Sorting Help
- Next Thread: no member function declared in class...weird behavior...
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






