New to C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 3
Reputation: eedythh2 is an unknown quantity at this point 
Solved Threads: 0
eedythh2 eedythh2 is offline Offline
Newbie Poster

New to C++

 
0
  #1
Dec 15th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 392
Reputation: StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light StuXYZ is a glorious beacon of light 
Solved Threads: 72
StuXYZ StuXYZ is offline Offline
Posting Whiz

Re: New to C++

 
0
  #2
Dec 15th, 2008
So what is your question ??
What is a loop??

A loop is a group of statements that get called multiple times
e.g.

  1. for(int i=0;i<10;i++)
  2. {
  3. // statements here
  4. }
which calls the statements 10 times
or
  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.
experience is the most expensive way to learn anything
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: New to C++

 
0
  #3
Dec 15th, 2008
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.
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 17
Reputation: AHUazhu is an unknown quantity at this point 
Solved Threads: 2
AHUazhu AHUazhu is offline Offline
Newbie Poster

Re: New to C++

 
0
  #4
Dec 15th, 2008
  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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,824
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 117
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: New to C++

 
0
  #5
Dec 15th, 2008
You need a stack to implement calculator.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: New to C++

 
0
  #6
Dec 15th, 2008
Originally Posted by ithelp View Post
You need a stack to implement calculator.
I don't think (s)he needs a stack for his/her question.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 628
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster

Re: New to C++

 
0
  #7
Dec 15th, 2008
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...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC