Why does my code not work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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;

12th Jul 2022, 4:34 AM
Amnesia YT
Amnesia YT - avatar
5 Answers
+ 1
After coding for 10 months and looking back to this i look so damn dumb 😭
23rd May 2023, 6:16 AM
Amnesia YT
Amnesia YT - avatar
+ 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.
12th Jul 2022, 4:58 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
int a, b, s; a = 56; b = 78; s = a+b; cout<<s;
12th Jul 2022, 7:34 AM
Coder Kay
Coder Kay - avatar
+ 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;
12th Jul 2022, 5:37 AM
Mihir Lalwani
Mihir Lalwani - avatar
+ 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!
12th Jul 2022, 9:13 AM
Vlad Apet