Concept explainers
C++
Write a while loop that prints userNum divided by 4 (integer division) until reaching 2 or less. Follow each number by a space. Example output for userNum = 160:
40 10 2
Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 160, then with userNum = 8, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks".
Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "
#include <iostream>
using namespace std;
int main() {
int userNum;
cin >> userNum;
/* Your solution goes here */
cout << endl;
return 0;
}
This is what I came up with but it produces no output
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- C++ Integers firstNum and secondNum are read from input. Complete the inner while loop so the inner loop executes firstNum * (secondNum + 1) times. Ex: If the input is 6 3, then the output is: Inner loop ran 24 timesarrow_forwardInteger userNum is read from input. Write a while loop that sums all integers read from input until the integer 1 is read. Integer 1 should not be included in the sum. Ex: If the input is 33 -4 -10 -35 1, then the output is: -16 1 #include 2 using namespace std; 3 4 int main() { 5 6 7 8 9 10 11 12 13 14 15 16 17 int userNum; int result; result = 0; cin >> userNum; while(userNum>0) { } result+=userNum; cin>>userNum; cout << result << endl;arrow_forwardC++ pls (use only while-loop. using for-loop will not get any credit.) Ask user how many grades you have. then ask them to enter those grades (this is a outer while-loop), then each time validate a grade(this is inner while-loop), then when you got all valid grades, find the average.arrow_forward
- c++ problemarrow_forwardC++ programming problem:arrow_forwardDistance Traveled, v 1.0 Purpose. The purpose of this lab is to perform a calculation repetitively within a loop. The loop may be either a while loop or a for loop. You are to write a program that calculates the distance a vehicle has traveled in a certain number of hours. Write a program called vehicle Trip.cpp to calculate the distance traveled for a given speed. Requirements. 1. Using the following formula: distance rate * time = calculate how many miles a vehicle has travelled in a certain number of hours. 2. Have the program ask the use for the speed of the vehicle (in miles per hour) and how many hours the vehicle has traveled. Do not accept a negative number for the speed of the vehicle, and do not accept a value less than 1 for hours the vehicle has traveled. 3. The program should use a loop to display the distance the vehicle has travelled for each hour of the time period that has been inputted. Program I/O. Input: Speed of the vehicle (in miles per hour), and Number of hours…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education