Question: Please help! Integer userNum is read from input. Write a while loop that iterates until userNum is negative. At each iteration: - Update integer finalVal
Please help!

Integer userNum is read from input. Write a while loop that iterates until userNum is negative. At each iteration: - Update integer finalVal as follows: - If userNum is not divisible by 5, output "lose" and do not update finalVal. - Otherwise, output "win" and increment finalVal. - Then, read an integer from input into variable userNum. End each output with a newline. Ex: If the input is 155111, then the output is: win win lose Final value is 2 Note: x%5==0 returns true if x is divisible by 5 . 567891011121314151617181920intuserNum;intfinalVal;finalVal=0;cin>>userNum;while(userNum>=0){if(userNum%5=0){finalVal+=userNum;}else{finalVal=userNum;}cin>>userNum; 1 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
