![]() |
| ||
| New to C++ 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... |
| ||
| Re: New to C++ So what is your question ?? What is a loop?? A loop is a group of statements that get called multiple times e.g. for(int i=0;i<10;i++)which calls the statements 10 times or while(x>18) 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. |
| ||
| Re: New to C++ 1. x as integer 2. y as integer 3. operator as char 4. get x from users 5. get y from users 6. get operator from users 7. switch operator, case '+': result=x+y, etc. 8. display result 9. whilerepeat, goto step 4 10. done. |
| ||
| Re: New to C++ int main() |
| ||
| Re: New to C++ You need a stack to implement calculator. |
| ||
| Re: New to C++ Quote:
|
| ||
| Re: New to C++ Yea - this question is clearly a "hello world" type program - they are obviously not getting into stacks yet. You're just confusing the issue instead of adding something constructive... |
| All times are GMT -4. The time now is 4:40 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC