| | |
New to C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 3
Reputation:
Solved Threads: 0
I'm very new to C++
I have an assignment where I have to create a calculator. Should work in console window and should allow user to enter 1st then 2nd number and then operator user wishes... In addition I have to use a switch statement. Not only that but it should run inside a loop. I don't even know how to start a loop...
command to exit if the ‘?’.
I'm a little lost...
I have an assignment where I have to create a calculator. Should work in console window and should allow user to enter 1st then 2nd number and then operator user wishes... In addition I have to use a switch statement. Not only that but it should run inside a loop. I don't even know how to start a loop...

command to exit if the ‘?’.
I'm a little lost...
•
•
Join Date: Nov 2008
Posts: 392
Reputation:
Solved Threads: 72
So what is your question ??
What is a loop??
A loop is a group of statements that get called multiple times
e.g.
which calls the statements 10 times
or
which calls the statements until x > 18. Note that if x is already
you don't get to run the statements in the loop.
There are other loop constructs, but for now: Write some code.
I would not try to do you assignment straight away, write a set of little test programs, e.g. print the number 1 to 10, then add them up.
then read a number from the keyboard etc. Post some code here, with a comment about what you can/can't understand and you will get a bit more useful feedback.
Note: We are not going to do you homework for you, but will help if you show effort.
What is a loop??
A loop is a group of statements that get called multiple times
e.g.
c++ Syntax (Toggle Plain Text)
for(int i=0;i<10;i++) { // statements here }
or
c++ Syntax (Toggle Plain Text)
while(x>18) { // Statements here }
which calls the statements until x > 18. Note that if x is already
you don't get to run the statements in the loop.
There are other loop constructs, but for now: Write some code.
I would not try to do you assignment straight away, write a set of little test programs, e.g. print the number 1 to 10, then add them up.
then read a number from the keyboard etc. Post some code here, with a comment about what you can/can't understand and you will get a bit more useful feedback.
Note: We are not going to do you homework for you, but will help if you show effort.
Last edited by StuXYZ; Dec 15th, 2008 at 2:33 am.
experience is the most expensive way to learn anything
•
•
Join Date: Dec 2008
Posts: 17
Reputation:
Solved Threads: 2
C++ Syntax (Toggle Plain Text)
int main() { int x,y; char opt; while(1) {std::cout<<"please input the x,y"<<endl; std:: cin>>x>>y; std::cout<<"please input the operate"<<endl; std::cin>>opt; switch (opt) case '+' : return x+y; case '-' : return x-y; . . ; } }
Last edited by AHUazhu; Dec 15th, 2008 at 4:57 am.
You need a stack to implement calculator.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Makefile
- Next Thread: wxwidgets App: how to get external socket input?
| Thread Tools | Search this Thread |
api array 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 parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






