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;
}
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.
#include<iostream>
usingnamespace 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.
}