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”.
#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;
}
Comments
Leave a comment