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;
}
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