Code:
Result:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int count = 0;
char input;
cout << "--------------------------" << endl;
cout << " Counter " << endl;
cout << "--------------------------" << endl;
cout << endl;
cout << "Press 1 to counter" << endl;
cout << "Press 0 to quit" << endl;
cout << endl;
cout << "Enter the number continuously : ";
while (true)
{
input = getch();
if (input == '1')
{
count += 1;
cout << "Your counts are " << count << endl;
}
else if (input == '0')
{
break;
}
}
cout << "-------------------------" << endl;
cout << "Your counts are " << count << endl;
return 0;
}
Result:
Comments
Post a Comment