im a complete beginner help!!!!

i really dont understand why its not working plz dont say how stupid i am. (i'm a complete beginner)
//
//
//
#include<iostream>
using namespace std;
int main ()
{
int i,n,p;
cout<<"enter a sum"<<endl;
cin>>n>>i;
p=n+i;
cout<<"the answer is...."<<p<<endl;
system("PAUSE");
}
{
int a,b,c;
cin>>a,b;
c=a*b;
cout<<"the answer is....."<<c<<endl;
}
Last edited on
If you are a complete beginner you will found all kind of help in
<a href="http://www.get-tuto.blogspot.com/">Tutorial</a>
Last edited on
There are several problems with your code, here's a working example, sorry, it was faster to fix it than to explain it, so just look at the changes and compare it with your original. I tried to show examples of different ways of getting similar results.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>
using namespace std;
int main ()
{
     int i = 0,n = 0,p = 0; // this isn't necessary, but blank variables have an undefined quantity which isn't actually 0.
     cout<<"enter a sum"<<endl;
     cin>>n>>i;
     p=n+i; 
     cout<<"the answer is...."<<p<<endl;


     cout<<"enter a new sum"<<endl;
     cin>>n>>i; //this writes over the variables that you called before
     n+=i; //this is the same as writing n = n + i
     cout<<"the answer is...."<<n<<endl;


     cout<<"looking for a product \n"; // "\n" inside of quotes does the same thing as endl;
     int a = 0,b = 0,c = 0;
     cin>>a; // the cin>>a,b part would have only put a value into a and left b blank
     cin>>b; // having 2 cin will do the same as cin>>a>>b;
     c=a*b;
     cout<<"the answer is....."<<c<<endl;
     system("PAUSE"); //this only needs to be placed where you need a pause, cin will cause it's own pause while waiting for input.
}
Last edited on
Topic archived. No new replies allowed.