943,566 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 40770
  • C++ RSS
Feb 11th, 2004
0

Add two numbers

Expand Post »
i need help for an engineering class is this the correct syntax for this type of program to add two numbers together i need help at the line that says here this is for a c++ source file



C++ Syntax (Toggle Plain Text)
  1. // program
  2.  
  3. #iomanip
  4. #iostream
  5.  
  6. include namespace std;
  7.  
  8. void main()
  9. {
  10. int number1,number2;
  11. char answer;
  12.  
  13. cout<<"number1";
  14. cin>>"number1";
  15.  
  16. cout>>"number2";
  17. cin>>"number2";
  18.  
  19. answer=number1+number2
  20.  
  21. here> cout<<char<<answer<<endl;
  22. }
Last edited by Nick Evan; Feb 16th, 2010 at 7:41 am. Reason: Added code-tags
Similar Threads
Reputation Points: 33
Solved Threads: 0
Junior Poster
J☼E is offline Offline
126 posts
since Feb 2004
Feb 12th, 2004
0

Re: help

I'm a newbe myself but this works:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int number1,number2,answer;
  6. cout << "number1? ";
  7. cin >> number1;
  8. cout << "number2? ";
  9. cin >> number2;
  10. answer = number1 + number2;
  11. cout << "Answer is " << answer;
  12. }

Hope this helps
Fishman
Last edited by Nick Evan; Feb 16th, 2010 at 7:41 am. Reason: Added code-tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fishman is offline Offline
7 posts
since Jan 2004
Feb 12th, 2004
0

Re: help

do you use microsoft visual c++?
Reputation Points: 33
Solved Threads: 0
Junior Poster
J☼E is offline Offline
126 posts
since Feb 2004
Feb 12th, 2004
0

Re: help

Hi Joe,

Fishman has given you some useful code their to get you going. Note that your own code has several basic syntax errors, which indicate that you're probably still at the "hello world" stage. Do you have a C++ book to refer to? If not, can you lay your hands on one for a little while? It'll help you enormously.

You can also find some (limited but) helpful stuff here:

http://www.robertjacobs.fsnet.co.uk/

Note that if you're using Visual C++ you'll probably have to add:

return 0;

just before the end of the main() function if you use fishman's code, otherwise you might get a compilation error.
Bob
Team Colleague
Reputation Points: 15
Solved Threads: 2
Junior Poster
Bob is offline Offline
129 posts
since Feb 2003
Mar 4th, 2010
-1
Re: Add two numbers
C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4.  
  5. {
  6.  
  7. float i,r,e;
  8.  
  9. cout<<"Entenr Any Number:\n";
  10. cin>>i;
  11.  
  12. cout<<"Enter Any Number:\n";
  13. cin>>r;
  14.  
  15. e=i+r;
  16.  
  17. cout<<e<<endl;
  18.  
  19.  
  20. return 0;
  21.  
  22. }
Last edited by Nick Evan; Mar 4th, 2010 at 4:21 am. Reason: Added code-tags
Reputation Points: 6
Solved Threads: 0
Newbie Poster
Robertwaffa is offline Offline
1 posts
since Mar 2010

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: error C2064
Next Thread in C++ Forum Timeline: Pointer to char..constructor is not working





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


Follow us on Twitter


© 2011 DaniWeb® LLC