Example 1
#include <iostream>
using namespace std;
int main()
{
int count=0;
double num, total = 0, average;
cout << "This program add the numbers you add."
<< "\n Enter 0 to exit and show average.";
do
{
cout << "\nEnter a number : ";
cin >> num;
if (num == 0)
break;
count++;
total = total + num;
cout << "\nThe total is : " << total;
} while (true);
average = total / count;
cout << "The total is : " << total
<< ". The average is : " << average;
return 0;
}
Example 2
#include <iostream>
using namespace std;
int main()
{
int opt;
do
{
cout << "\nMain Menu"
<< "\n========="
<< "\n1. Calculator"
<< "\n2. Temp Converter"
<< "\n3. Exit"
<< "\nEnter your option:";
cin >> opt;
switch (opt)
{
case 1:
cout << "Opening calculator application";
break;
case 2:
cout << "Opening Temp Converter application";
break;
case 3:
cout << "Exiting program";
exit(0);
break;
default:
cout << "Invalid option";
break;
}
} while (true);
return 0;
}
Comments
Post a Comment