943,866 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 526
  • C++ RSS
Dec 15th, 2008
0

New to C++

Expand Post »
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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
eedythh2 is offline Offline
3 posts
since Dec 2008
Dec 15th, 2008
0

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.

c++ Syntax (Toggle Plain Text)
  1. for(int i=0;i<10;i++)
  2. {
  3. // statements here
  4. }
which calls the statements 10 times
or
c++ Syntax (Toggle Plain Text)
  1. while(x>18)
  2. {
  3. // Statements here
  4. }

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.
Reputation Points: 732
Solved Threads: 134
Practically a Master Poster
StuXYZ is offline Offline
659 posts
since Nov 2008
Dec 15th, 2008
0

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. while repeat, goto step 4
10. done.
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Dec 15th, 2008
0

Re: New to C++

C++ Syntax (Toggle Plain Text)
  1. int main()
  2. {
  3. int x,y;
  4. char opt;
  5. while(1)
  6. {std::cout<<"please input the x,y"<<endl;
  7. std:: cin>>x>>y;
  8. std::cout<<"please input the operate"<<endl;
  9. std::cin>>opt;
  10. switch (opt)
  11. case '+' : return x+y;
  12. case '-' : return x-y;
  13. .
  14. .
  15. ;
  16. }
  17. }
Last edited by AHUazhu; Dec 15th, 2008 at 4:57 am.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
AHUazhu is offline Offline
17 posts
since Dec 2008
Dec 15th, 2008
0

Re: New to C++

You need a stack to implement calculator.
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006
Dec 15th, 2008
0

Re: New to C++

Click to Expand / Collapse  Quote originally posted by ithelp ...
You need a stack to implement calculator.
I don't think (s)he needs a stack for his/her question.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Dec 15th, 2008
0

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...
Featured Poster
Reputation Points: 437
Solved Threads: 204
Posting Virtuoso
daviddoria is offline Offline
1,968 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Makefile
Next Thread in C++ Forum Timeline: wxwidgets App: how to get external socket input?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC