Question

for C++ Write a function containing a while loop that lets the user enter a number....

for C++

Write a function containing a while loop that lets the user enter a number. The number should be multiplied by 10, and the result stored in the variable product . The loop should iterate as long as product contains a value less than 100. Have the function return product.

Homework Answers

Answer #1
#include <iostream>

using namespace std;

int get_product() {
    int number, product = 0;
    while (product < 100) {
        cout << "Enter a number: ";
        cin >> number;
        product = number * 10;
    }
    return product;
}

int main() {
    cout << "Product is " << get_product() << endl;
    return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a MATLAB while-loop code that asks a user to enter an integer number until its...
Write a MATLAB while-loop code that asks a user to enter an integer number until its factorial is smaller than 100.
Write a while loop to ask the user to type number of hours(double) they work per...
Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than or equal to 0 and less than 5, then:  salary = numberofhours * 5, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 10, then: salary = numberofours * 8, loop continues, the user can type...
Write the C++ language statements to ask a user to enter a number within the range...
Write the C++ language statements to ask a user to enter a number within the range of 0 to 100 (0 and 100 are valid inputs). When the value is not valid, you should prompt the user to enter another value. (The user may enter many invalid numbers, so you must use loop). Only after the user enters a valid number should you display the message “Good” and the value of the number.
C++ please Write a program that allows a user to enter any number of product prices...
C++ please Write a program that allows a user to enter any number of product prices and show the total of all of the products. Use 0.00 as a sentinel value. (while loop)
Write a function using while loop, add the number to 10, then return the product to...
Write a function using while loop, add the number to 10, then return the product to the main function. Use double.
Write the function definition for a function that requests the user to enter an integer between...
Write the function definition for a function that requests the user to enter an integer between 19 and 47 (both exclusive). Repeat (loop) within the function until a valid number is entered. Return the user’s number using a reference parameter.
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter an number. Then, it asks for a second number. These will use the "input" command. Store these as two separate variables. This function takes NO arguments and is also a VOID function, there is no return statement. The function should print the result of these two numbers multiplied together. The program should be able to multiply floats. For example: Test Input Result calculateInput() 5...
Using a for Loop visual c++ Summary In this lab the completed program should print the...
Using a for Loop visual c++ Summary In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and...
VISUAL BASIC FOR APPLICATIONS PLEASE! Create an application that lets the user enter a number of...
VISUAL BASIC FOR APPLICATIONS PLEASE! Create an application that lets the user enter a number of seconds and produces output according to the following criteria: There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or...