954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Add two numbers

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;
}
J&#9788;E
Junior Poster
126 posts since Feb 2004
Reputation Points: 33
Solved Threads: 0
 

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

fishman
Newbie Poster
7 posts since Jan 2004
Reputation Points: 10
Solved Threads: 0
 

do you use microsoft visual c++?

J&#9788;E
Junior Poster
126 posts since Feb 2004
Reputation Points: 33
Solved Threads: 0
 

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
Junior Poster
Team Colleague
129 posts since Feb 2003
Reputation Points: 15
Solved Threads: 2
 
#include<iostream>
using namespace std;
int main()

{

float i,r,e;

cout<<"Entenr Any Number:\n";
cin>>i;

cout<<"Enter Any Number:\n";
cin>>r;

e=i+r;

cout<<e<<endl;


return 0;

}
Robertwaffa
Newbie Poster
1 post since Mar 2010
Reputation Points: 6
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You