0

when I run the code and enter the value of 'a' a letter instead of showing the erroe it's showing the sum.!? and on entering hig

#include <iostream> using namespace std; int main() { int a,b; cout << "enter the value of 'a' \n "; cin >> a; cout << "enter the value of 'b' \n "; cin >> b; int sum = a+b; cout <<"The sum is: " << sum << endl; return 0; }

19th Dec 2018, 9:17 AM
Aditya Rathore
Aditya Rathore - avatar
1 Resposta
+ 1
That's because it implicitely casts the char into an int. chars (letters) correspond to an integer value, which can be found in the so called ASCII table. If you don't want this to happen, you first have to check the variable type. Or use different compiler flags, to avoid implicit casting (doesn't work in Sololearn though, because you have no access to it).
19th Dec 2018, 9:22 AM
Matthias
Matthias - avatar