could anyone tell why if i enter any digit lower than 5 output cones to be 5 but if more than 5 say 6 ans is 30 y so? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

could anyone tell why if i enter any digit lower than 5 output cones to be 5 but if more than 5 say 6 ans is 30 y so?

https://www.sololearn.com/learn/CPlusPlus/1615/ this the link and it is in third page

6th Apr 2018, 11:31 AM
Sahil Chauhan
Sahil Chauhan - avatar
2 Answers
+ 6
#include <iostream> using namespace std; int main() { int num = 1; int number; int total = 0; //value of num=1 to 5 so till the value of num 5 the while loop body will execute //total =0 initially while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl; return 0; } for the ex:- number =6 so it goes in while loop body till the num value 5 so num=1 =>total=0+6=6 num=2 =>total=6+6=12 num=3 =>total=12+6=18 num=4 =>total=18+6=24 num=5 =>total=24+6=30 so the output came 30 so this code just add the number enter by user five times
6th Apr 2018, 11:56 AM
GAWEN STEASY
GAWEN STEASY - avatar
0
Hi Sahil That link gives a 404, and you have no code associated with your profile. Do you still need help?
6th Apr 2018, 11:37 AM
Emma