Write a program that takes two numbers as input, assigns those values to the provided a and b variables, then outputs their sum. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Write a program that takes two numbers as input, assigns those values to the provided a and b variables, then outputs their sum.

Please let me know where i went wrong!!!!!! #include <iostream> using namespace std; int main() { int a; int b; int sum; cout << "Enter the value a:"; cin>> a; cout<<"\nEnter the value b:"; cin >> b; sum=a+b; cout<< "\nThe sum is:"<<sum ; return 0; }

16th Jan 2022, 6:43 AM
_pfttwdyc_
_pfttwdyc_ - avatar
7 Answers
+ 6
_pfttwdyc_ , i assume that your question is a code coach exercise. please note: ▪︎all code coach exercises are tested by a program that passes values for the various test cases and that receives results from the code. this will work perfectly, as long as only the demanded inputs and / or outputs are used in our codes. ▪︎so please do not use any *user prompt* in your code, and only print the required results without any additional output.
16th Jan 2022, 9:02 AM
Lothar
Lothar - avatar
+ 4
Try to comment the lines that prints input prompts ("Enter the value ...") And print <sum> only, without "\nThe sum is ..."
16th Jan 2022, 7:03 AM
Ipang
+ 3
What correction is needed? the code works as expected ... Please use proper tags ... ☝ https://code.sololearn.com/W3uiji9X28C1/?ref=app
16th Jan 2022, 6:49 AM
Ipang
+ 2
This code is right. You have to give input like this in sololearn: Input... x (say) y (say)
16th Jan 2022, 7:01 AM
NEZ
NEZ - avatar
+ 1
Oops I thought it was not a code coach problem 🙄
16th Jan 2022, 7:08 AM
NEZ
NEZ - avatar
+ 1
#include <iostream> using namespace std; int main() { int a; int b; // your code goes here cin>> a>>b; int sum=a+b; cout<<sum; return 0; }
14th Nov 2022, 7:06 AM
Savannah
Savannah - avatar
0
But the result says to try again and something went wrong
16th Jan 2022, 7:00 AM
_pfttwdyc_
_pfttwdyc_ - avatar