Exercise 7.2 : Taking Inputs (User Input) | Sololearn: Learn to code for FREE!
+ 2

Exercise 7.2 : Taking Inputs (User Input)

‚ÄúWrite a program that takes two numbers as input, assigns those values to the provided a and b variables, then outputs their sum.‚ÄĚ I‚Äôm lost. I‚Äôve tried numerous times to code it correctly. Int a = 5; Int b = 20; Int sum = a + b; Cout << ‚ÄúFind the sum of two numbers.‚ÄĚ ; Cin >> sum >> endl;

19th Feb 2021, 12:38 AM
TahitiūüĆćCastillo
TahitiūüĆćCastillo - avatar
21 Respostas
+ 10
Hey, Tahiti ūü•≥ūü•≥ Congratulations ! ūüéä You solved it on your own. Great job ūüĎŹ Just saw your posts, wasn't around to help you today.
20th Feb 2021, 1:09 AM
Shivani ūüďö‚úć
Shivani ūüďö‚úć - avatar
+ 4
You have to take input for a and b. Whenever you assign the value to variable, you fail to take inputs. We learned this in [input] lesson. ūüĎá // To enable the user to input a value, use cin in combination with the extraction operator (>>). Try once again. Understand the given description in problem. Re-read / refer again that's in lesson. Let us know if you were able to solve. Note: the first letter should not be in capital letter for [cout] & [cin]
19th Feb 2021, 12:49 AM
Shivani ūüďö‚úć
Shivani ūüďö‚úć - avatar
+ 4
Tahiti "lvalue" ūüĎá An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address). Another value is "rvalue"ūüĎá rvalues are defined by exclusion. Every expression is either an lvalue or an rvalue, so, an rvalue is an expression that does not represent an object occupying some identifiable location in memory. You can refer to the link shared below for understanding better ūüĎá https://www.internalpointers.com/post/understanding-meaning-lvalues-and-rvalues-c hey, little more help for you for tagging the person [ use @ before name, so they will get notified when you asking for help ]
20th Feb 2021, 2:31 AM
Shivani ūüďö‚úć
Shivani ūüďö‚úć - avatar
+ 3
Tahiti , you have to calculate a & b How you can solve if you are already assigning values of 5 & 20?
19th Feb 2021, 12:54 AM
Shivani ūüďö‚úć
Shivani ūüďö‚úć - avatar
+ 2
Thank you very much, Arsenic ! Maybe I‚Äôm making this more difficult than it really is. I tried again, and I get ‚ÄúLine 12: expected initializer before ‚Äė>>‚Äô token. I‚Äôll try that link.
19th Feb 2021, 1:33 AM
TahitiūüĆćCastillo
TahitiūüĆćCastillo - avatar
+ 2
Tahiti , I am learner & keep learning. Didn't mastered languages. Because, programming languages are always updating and have more functionality. So, just keep learning.
20th Feb 2021, 12:59 PM
Shivani ūüďö‚úć
Shivani ūüďö‚úć - avatar
+ 1
Tahiti check this lesson to learn how to get user input using cin ūüĎá https://www.sololearn.com/learning/1607/
19th Feb 2021, 12:55 AM
Arsenic
Arsenic - avatar
+ 1
Thank you, Shivani! Maybe you can still help. I really didn‚Äôt understand the direction (error message) that said: line 11 lvalue required as left operand of assignment What is ‚Äúlvalue‚ÄĚ ?
20th Feb 2021, 1:29 AM
TahitiūüĆćCastillo
TahitiūüĆćCastillo - avatar
+ 1
Shivani ūüďö‚úć Yes, I certainly will do that!
20th Feb 2021, 6:07 PM
TahitiūüĆćCastillo
TahitiūüĆćCastillo - avatar
+ 1
That's it: #include <iostream> using namespace std; int main() { int a; int b; // your code goes here cin >> a; cin >> b; cout << a + b; return 0; }
28th Jul 2021, 7:11 PM
Octavian Malinici-Pruteanu
Octavian Malinici-Pruteanu - avatar
+ 1
Solution: #include <iostream> using namespace std; int main(){ int a; int b; a=1; b=4; cin>>a; cin>>b; cout<<a+b; return 0; }
21st Oct 2021, 5:58 AM
Rugema Didier
+ 1
#include <iostream> using namespace std; int main() { int a; int b; // your code goes here cin>>a; cin>>b; cout<<a+b; return 0; }
6th Nov 2022, 10:20 AM
Be Rain
Be Rain - avatar
0
Do it according to what question says. 1. Take input (use cin) and put the value in variable "a" 2. Take another input and put the value in variable "b" 3. Calculate "a+b" 4. Output the sum on the screen (use cout)
19th Feb 2021, 12:46 AM
Arsenic
Arsenic - avatar
0
cin >> 5; cin>> 20; cout << ‚Äú25‚ÄĚ‚ÄĚ>>; Correct?
19th Feb 2021, 12:51 AM
TahitiūüĆćCastillo
TahitiūüĆćCastillo - avatar
0
I will get this right, I don‚Äôt care how many tries it takes. Please be mindful that I‚Äôm brand new to C++ this week. Here‚Äôs what I have now: 7 cout << ‚ÄúEnter a number. \n‚ÄĚ ; 8 cin >> a; 9 cout << ‚ÄúEnter another number. \n‚ÄĚ; 10 cin >> b; 11 a = 3 << b = 5; 12 int sum; 13 sum = a + b; 14 cout << ‚ÄúSum is: ‚Äú << sum; line 11 lvalue required as left operand of assignment cout << ‚ÄúHelp!!!! ūüė≠ ‚Äú ;
20th Feb 2021, 12:09 AM
TahitiūüĆćCastillo
TahitiūüĆćCastillo - avatar
0
And also, thank you very much for your help, Shivani! And thank you, Mr. Imperfect!
20th Feb 2021, 12:11 AM
TahitiūüĆćCastillo
TahitiūüĆćCastillo - avatar
0
I finally solved it!!! I couldn‚Äôt believe it. ūü•≥
20th Feb 2021, 12:39 AM
TahitiūüĆćCastillo
TahitiūüĆćCastillo - avatar
0
Thanks a million, Shivani ūüďö‚úć ! And WOW, all those languages you‚Äôve mastered! Incredible! ūüŹÜ
20th Feb 2021, 10:53 AM
TahitiūüĆćCastillo
TahitiūüĆćCastillo - avatar
0
Write a program that takes two numbers as input, assigns those values to the provided a and b variables, then outputs their sum. I have tried numerouse attempts but nothing is going right.
10th Jul 2021, 2:20 PM
Mahki Wimbish
Mahki Wimbish - avatar
0
#include <iostream> using namespace std; int main () { int a; int b; cin>>a; cin>>b; int sum=a+b; cout<<sum<<endl; return 0; } The above code will give you correct output ūüėá
14th Nov 2021, 6:01 AM
Komal Bramhaji Jondhale
Komal Bramhaji Jondhale - avatar