Post: im confused on how this works
05-11-2017, 01:47 AM #1
(adsbygoogle = window.adsbygoogle || []).push({});
    #include <iostream>
using namespace std;

int main(){
int x;
int y;
int subtraction=x-y;

cout<< "enter an num\n";
cin>>x;
cout<< "one more\n";
cin>>y;
cout<< "answer is\n";
cout<<subtraction;
return 0;
}

why does this program not subtract properly but the one on the bottom does???
    #include <iostream>
using namespace std;

int main(){
int x;
int y;
int subtraction;

cout<< "enter an num\n";
cin>>x;
cout<< "one more\n";
cin>>y;
cout<< "answer is\n";
subtraction=x-y;
cout<<subtraction;
return 0;
}
05-15-2017, 09:12 AM #2
In the first example you affect a value to a variable through an operation with variables that weren't initialized. You can't magically expect the computer to know which numbers the user will input.

The following user thanked theDaftDev for this useful post:

mudville209

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo