| | |
New to C++
![]() |
•
•
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: 378
Reputation:
Solved Threads: 71
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 bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error faq file forms fstream function functions game givemetehcodez graph gui hash homeworkhelp homeworkhelper iamthwee ifpug ifstream infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






