171k views
4 votes
Write a program that asks you to enter some integers, and press "enter" after each one.

There will be no set number of integers, and no need for data checking.

Entering the integer 0 will end the process of entering the integers

1 Answer

3 votes

Answer:

// here is code in c++.

// headers

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variables

int num;

cout<<"enter an integer (0 to stop):";

// read the integer

cin>>num;

// read integer until user enter 0

while(num)

{

cout<<"enter an integer (0 to stop):";

cin>>num;

}

//if input is 0 then print "exit"

cout<<"exit"<<endl;

return 0;

}

Step-by-step explanation:

Declare a variable "num" to read input from user.Read input integer until

user enter 0 as input.When user enter 0 then program will print "exit" and

end the program.

Output:

enter an integer (0 to stop):2

enter an integer (0 to stop):-2

enter an integer (0 to stop):4

enter an integer (0 to stop):10

enter an integer (0 to stop):123

enter an integer (0 to stop): 0

exit

User I Want Badges
by
6.5k points