0

What did I do wrong here?

Idid this #include <iostream> using namespace std; //change int main() { int a; int b; int sub = a-b; cout <<"Cash" <<endl; cin >>a; cout <<"Cost" <<endl; cin>> b; cout <<"The change is:" <<sub <<endl; return 0; }

20th Jul 2016, 12:57 PM
smr
4 Answers
+ 2
when you declarete the variable sub you puts the value of null because you tried to quit none units to a none value int a; int b; int sub=a-b; now a=0 and b=0 and 0-0=0 to solve this you only need to declarete the variable sub whit any value and at the end of getting input puts the value of sub like this int main (){ int a; int b; int sub; cout <<"something"<<endl; cin>>a; cout <<"other thing"<<endl; cin>>b; sub=a-b; cout <<sub <<endl; return 0; }
20th Jul 2016, 1:17 PM
Ismael Perbech
Ismael Perbech - avatar
0
nothing here any errors.. good... keep it up!
20th Jul 2016, 1:12 PM
meherDev
meherDev - avatar
0
Ah, ok thanks. I thought it was wrong because the app doesn't run it properly...but thank you
20th Jul 2016, 1:15 PM
smr
0
Oh, it's true. Now it works. Thank you.
20th Jul 2016, 1:26 PM
smr