I am writing a program where the user enters postive numbers and the program outputs the average, and then asks the user if they want to repeat the program....I got the average part to work, but I can't seem to figure out how to get the program to ask the user if they want to do it again
#include <iostream>
usingnamespace std;
double average();
char chr;
int main()
{
cout << "The avergae is: " << average() << endl;
}
double average()
{
double input = 0;
double total = 0;
int count = 0;
double average;
do
{
cout << "Enter a stream of positive numbers (0 or above)." << endl;
cout << "Enter a negative number when you are finished." << endl;
cin >> input;
if (input >= 0)
{
total = input + total;
count++;
}
}
while (input >= 0);
average = total / count;
return average;
char answer;
do
{
cout << "Would you like to repeat? Enter Y/N";
cin >> answer;
if ('N')
cout << "Thanks for playing!";
}
while (answer = 'Y');
cin >> chr;
return 0;
}
#include <iostream>
usingnamespace std;
double average();
int main()
{
char answer;
do
{
cout << "The avergae is: " << average() << endl << endl;
cout << "Would you like to repeat? Enter Y/N: ";
cin >> answer;
} while(answer == 'Y');
cout << "Thanks for playing!";
return 0;
}
double average()
{
double input = 0;
double total = 0;
int count = 0;
double average;
do
{
cout << "Enter a stream of positive numbers (0 or above)." << endl;
cout << "Enter a negative number when you are finished." << endl;
cin >> input;
if (input >= 0)
{
total = input + total;
count++;
}
}
while (input >= 0);
average = total / count;
return average;
}
char answer;
do
{
cout << "Would you like to repeat? Enter Y/N";
cin >> answer;
// Stuff goes in here ??
} while (answer == 'Y');
cout << "Thanks for playing!";