+ 3
Variables problem
#include<iostream> using namespace std; int main (){ int a = 5; int b = 2; cin >> a; cin >> b; int sum = a + b; cout<< sum; return 0; } What’s wrong with that code ? Every time I run it it just gives me 14 which Is the wrong answer. It is supposed to be 7.
7 odpowiedzi
+ 1
#include<iostream>
using namespace std;
int main (){
int a = 5;
int b = 2;
int sum = a + b;
cout<< sum;
return 0;
}
Or
#include<iostream>
using namespace std;
int main (){
cin >> a;
cin >> b;
int sum = a + b;
cout<< sum;
return 0;
}
+ 1
Why can’t we write cin , declare and assign the value at the same code ?
+ 1
Thanks ✨
+ 1
The second one isn’t working properly
+ 1
You can, only as you see, this leads to incorrect results. although in theory, after entering values manually, the value previously entered in the variable should disappear. try to figure it out why this is happening
0
Explanation: 20% of 50 is 10.
To calculate 20% of a given amount, you can multiply the number by 20 and divide it by 100: 50*20/100 = 10.0
please write code In python