-1

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;
}

Edited by Nick Evan: Added code-tags

5
Contributors
5
Replies
23
Views
13 Years
Discussion Span
Last Post by NANDHINI G
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

Edited by Nick Evan: Added code-tags

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.

-1
#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;

}

Edited by Nick Evan: Added code-tags

Votes + Comments
The only useful thing in this thread is Joe's avatar; your post being 6 years late is too useless to worth a mention.
-1
/*Program to add two numbers*/
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
cout<<"\nEnter the value for a:";
cin>>a;
cout<<"\nEnter the value for b:";
cin>>b;
cout<<"\nThe sum of a and b is:"<<a+b;
getch();
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.