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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double getMax(double firstnum, double secondnum)
{
if( firstnum > secondnum) return firstnum;
else return secondnum;
}
int main()
{
do
{
double firstnum, secondnum, thirdnum, fourthnum, fifthnum;
char operation;
char ans;
cout << "Hello there! Please enter up to five numbers. If you wish to enter less than \n five, please make your last number negative. Please enter a minimum of \ntwo numbers" << endl;
cout << "please enter your first number: " << endl;
cin >> firstnum;
cout << "please enter your second number: " << endl;
cin >> secondnum;
if (secondnum < 0) {
cout << "please enter + for addition, M for maximum, or A for average: " << endl;
cin >> operation;
if (operation == '+')
cout << setiosflags(ios::fixed) << "The numbers add to: " << abs(secondnum)+ abs(firstnum) << endl;
else if(operation == 'A')
cout << setiosflags(ios::fixed) << "The average of the numbers is: "<< (abs(secondnum)+abs(firstnum))/2 << endl;
else if(operation == 'M')
cout << setiosflags(ios::fixed) << "The maximum number is: " << getMax(abs(firstnum), abs(secondnum)) << endl;
cout << " would you like to try again (y/n)?";
cin >> ans;
}
else
cout << "please enter your third number: " << endl;
cin >> thirdnum;
if (thirdnum < 0) {
cout << setiosflags(ios::fixed) << "please enter + for addition, M for maximum, or A for average: " << endl;
cin >> operation;
if (operation == '+')
cout << setiosflags(ios::fixed) << "The numbers add to: " << abs(secondnum)+abs(firstnum)+abs(thirdnum) << endl;
else if(operation == 'A')
cout << setiosflags(ios::fixed) << "The average of the numbers is: "<< (abs(secondnum)+abs(firstnum)+abs(thirdnum))/2 << endl;
cout << " would you like to try again (y/n)?";
cin >> ans;
}
else
cout << "please enter your fourth number:" << endl;
cin >> fourthnum;
if (fourthnum < 0) {
cout << setiosflags(ios::fixed) << "please enter + for addition, M for maximum, or A for average: " << endl;
cin >> operation;
if (operation == '+')
cout << setiosflags(ios::fixed) << "The numbers add to: " << abs(secondnum)+abs(firstnum)+abs(thirdnum)+abs(fourthnum) << endl;
else if(operation == 'A')
cout << setiosflags(ios::fixed) << "The average of the numbers is: "<< (abs(secondnum)+abs(firstnum)+abs(thirdnum)+abs(fourthnum))/2 << endl;
cout << " would you like to try again (y/n)?";
cin >> ans;
}
else
cout << "please enter your fifth number:" << endl;
cin >> fifthnum;
{
cout << "please enter + for addition, M for maximum, or A for average: " << endl;
cin >> operation;
if (operation == '+')
cout << setiosflags(ios::fixed) << "The numbers add to: " << abs(secondnum)+abs(firstnum)+abs(thirdnum)+abs(fourthnum)+abs(fifthnum) << endl;
else if(operation == 'A')
cout << setiosflags(ios::fixed) << "The average of the numbers is: "<< (abs(secondnum)+abs(firstnum)+abs(thirdnum)+abs(fourthnum)+abs(fifthnum))/2 << endl;
cout << " would you like to try again (y/n)?";
cin >> ans;
}
}
while(ans == y);
system("pause");
return 0;
}
|