0
Why does my code not work
Im a beginner and just wanted to try this from the comments but it doesn't work, it's supposed to add up to 100 int a, b, sum; int a = 48; int b = 52; cout << sum;
5 Answers
+ 1
After coding for 10 months and looking back to this i look so damn dumb đ
+ 4
You don't add anywhere. How do you expect sum to be 100 if you don't assign the result of an expression to it?
sum = a + b;
Then sum holds the sum of a and b.
+ 2
int a, b, s;
a = 56;
b = 78;
s = a+b;
cout<<s;
+ 1
sum=a+b;
cout<<sum;
You need to add the sum of a and b
assigning It to a sum variable
Then print it
You can also direct print the sum by
Cout<<a+b;
+ 1
You haven't applied any operation on sum, look:
int a, b, sum;
int a = 48;
int b = 52;
sum = a + b; // this is what you forgot to do.
cout << sum;
you also can do this:
int a, b;
int a = 48;
int b = 52;
cout << a + b;
(You can find more explanations in Lesson 8.1 of the C++ course) Good luck!