Answer to Question #283945 in C++ for Abdullah

Question #283945

Write a program that will ask the user If he wants to enter a number. If the user will

enter “Y” then multiply all the numbers entered by user. The program will keep on

asking the user if he wants to enter a number until he enters “N”.


1
Expert's answer
2021-12-31T08:58:57-0500
#include <iostream>
using namespace std;

int main() {
    char ans;

    cout << "Do you want to enter a number? ";
    cin >> ans;
    if (ans != 'Y') {
        return 0;
    }

    int product = 1;
    int x;
    do {
        cout << "Enter a number: ";
        cin >> x;
        product *= x;
        cout << "Do you want to enter another number? ";
        cin >> ans;
    } while (ans != 'N');

    cout << "The product of the numbers is " << product << endl;

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog