0

int num = 1; int number; int total = 0; while (num <= 5) { Ā  cin >> number; total += number; Ā  num++; } cout << total << endl;

why is total=0šŸ˜?

3rd Dec 2017, 3:31 PM
Mitra
Mitra - avatar
8 Answers
+ 3
First, there is a variable named number which is undefined, in line 2 You have to give number a value in order to add it in total Otherwise, everytime total will result in 0
3rd Dec 2017, 4:36 PM
#RahulVerma
#RahulVerma - avatar
+ 1
ok
3rd Dec 2017, 3:57 PM
Mitra
Mitra - avatar
+ 1
Your code is true. In this app, you must type all of inputs(here ints) that the code wants by pressing enter key between.
7th Dec 2017, 8:23 PM
Mahdi Ghahramani
Mahdi Ghahramani - avatar
0
why is it nessesery?
3rd Dec 2017, 3:46 PM
Mitra
Mitra - avatar
0
it's not?
3rd Dec 2017, 3:54 PM
Mitra
Mitra - avatar