1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include<iostream>
#include<cmath>
using namespace std;
const double SIZE = 5;
void getValues(double numbers[],double SIZE);
void showMenu();
void getChoice(char & choice );
void doTheMath(double numbers[],double SIZE,double & root, double & sum, double & average, char & choice);
int main()
{
double numbers[SIZE];
char choice;
double root;
double sum;
double average;
getValues(numbers,SIZE);
showMenu();
getChoice(choice);
doTheMath(numbers,SIZE,root,sum,average,choice);
}
void getValues(double numbers[],double SIZE)
{
cout << "Enter 5 numbers:\n";
for(int i = 0; i<SIZE; i++)
{
cout << i + 1 <<".";
cin >> numbers[i];
}
system("cls");
}
void showMenu()
{
cout << "A.Display the Square Root of each number.\n"
<< "B.Display the Sum of all numbers.\n"
<< "C.Display the average of all numbers.\n\n\n";
}
void getChoice(char & choice )
{
cout << "Enter your choice: ";
cin >> choice;
system("cls");
}
void doTheMath(double numbers[],double SIZE,double & root, double & sum, double & average, char & choice)
{
switch (choice)
{
case 'A': cout << "The square roots are.\n\n";
for (int i = 0; i<SIZE; i++)
{
root = sqrt(double(numbers[i]));
cout << "#" << i+1 << ": " << root << endl;
}
case 'a':
break;
case 'B': cout << "The sum of all numbers is\n\n";
for (int i = 0; i<SIZE; i++)
{
sum += numbers[i];
}
case 'b':
break;
case 'C': cout << "The average of the numbers is\n\n\";
average = double (sum) / double(SIZE);
case 'c':
break;
default: cout << "Invalid entry";
break;
}
}
|