Based on Control Structure Selection and Control Structure Looping, answer the following questions:
Write a program that will ask the user to input n positive numbers. The program will terminate if one of those numbers is not positive. Output :
https://cdn.discordapp.com/attachments/711213157854609461/839150310864846934/unknown.png
#include <iostream>
using namespace std;
int main()
{
const int n=100;
for(int i=0; i<n; i++) {
int x;
cout << "Enter a number:";
cin >> x;
if (x <= 0) {
break;
}
cout << endl;
}
}
Comments
Leave a comment