Add two numbers

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

Join Date: Feb 2004
Posts: 126
Reputation: J☼E is an unknown quantity at this point 
Solved Threads: 0
J☼E's Avatar
J☼E J☼E is offline Offline
Junior Poster

Add two numbers

 
0
  #1
Feb 11th, 2004
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



// program

#iomanip
#iostream

include namespace std;

void main()
{
int number1,number2;
char answer;

cout<<"number1";
cin>>"number1";

cout>>"number2";
cin>>"number2";

answer=number1+number2

here> cout<<char<<answer<<endl;
}
Reply With Quote Quick reply to this message  
Join Date: Jan 2004
Posts: 7
Reputation: fishman is an unknown quantity at this point 
Solved Threads: 0
fishman fishman is offline Offline
Newbie Poster

Re: help

 
0
  #2
Feb 12th, 2004
I'm a newbe myself but this works:
#include <iostream>
using namespace std;
int main()
{
int number1,number2,answer;
cout << "number1? ";
cin >> number1;
cout << "number2? ";
cin >> number2;
answer = number1 + number2;
cout << "Answer is " << answer;
}

Hope this helps
Fishman
Reply With Quote Quick reply to this message  
Join Date: Feb 2004
Posts: 126
Reputation: J☼E is an unknown quantity at this point 
Solved Threads: 0
J☼E's Avatar
J☼E J☼E is offline Offline
Junior Poster

Re: help

 
0
  #3
Feb 12th, 2004
do you use microsoft visual c++?
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 129
Reputation: Bob is an unknown quantity at this point 
Solved Threads: 1
Team Colleague
Bob Bob is offline Offline
Team Member

Re: help

 
0
  #4
Feb 12th, 2004
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.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC