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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <algorithm>
/*These are function prototypes.
The whole purpose of having these is to tell the compiler that these
functions do exist but their code is listed somewhere else in the program
(That way the compiler doesn't complain about functions that don't exist)*/
int get_mid(int,int,int);
int get_max(int,int,int);
int get_min(int,int,int);
using namespace std;
int main()
{
//Get all the characters out of the way(Okay practice but w.e)
int choice;
int numb1;
int numb2;
int numb3;
int sum;
int sum1;
int Max;
int Min;
int Mid;
//Print the menu and the get the persons selection
start:
cout <<"Choose Option ";
cin>>choice;
/*Remember that if you have an "If" statement or a
statement in general with more than
One line of code in it then you'll need to put it in a block or
parenthesis(Depends who you are) {}*/
//Option 1
if (choice ==1)
{
cout << "Please Enter The first integer: ";
cin >> numb1;
cout << "Please Enter The second integer: ";
cin >> numb2;
cout << "Please Enter The third integer: ";
cin >> numb3;
sum = numb1 + numb2 + numb3;
cout << "And The Sum is " << sum << endl;
cout << "OPTION 1"<<endl;
return 0;
}
//Option 2
if ( choice ==2 )
{
cout << "Please Enter The first integer: ";
cin >> numb1;
cout << "Please Enter The second integer: ";
cin >> numb2;
cout << "Please Enter The third integer: ";
cin >> numb3;
sum = numb1 - numb2 - numb3;
cout << "And The Sum is " << sum << endl;
cout << "OPTION 2"<<endl;
return 0;
}
//Choice 3 of application
if (choice==3)
{
cout << "Please Enter The first integer: ";
cin >> numb1;
cout << "Please Enter The second integer: ";
cin >> numb2;
sum = numb1 - numb2;//Don't forget your semicolon
cout << "Please Enter The third integer: ";
cin >> numb3;
sum1= sum - numb3;//Once again...
if(sum < sum1) //if the first sum is less than the second
{
std::cout << "The lowest sum is: " << sum; //print the first sum
}
else if(sum1 < sum) //else if the second sum is smaller
{
std::cout << "The lowest sum is: " << sum1; //print the second sum
}
else //accounts for the case that they're equal
{
std::cout << "They're both equal at " << sum;
}
cout << "OPTION 3"<<endl;
return 0;
}
//OPTION 4
if (choice == 4)
{
cout << "Please Enter The first integer: ";
cin >> numb1;
cout << "Please Enter The second integer: ";
cin >> numb2;
cout << "Please Enter The third integer: ";
cin >> numb3;
Max = get_max(numb1,numb2,numb3);
cout << "The max : " << Max << endl;
Min = get_min(numb1,numb2,numb3);
cout << "The min : " << Min << endl;
Mid = get_mid(numb1,numb2,numb3);
cout << "The mid : " << Mid << endl;
cout << "OPTION 4"<<endl;
return 0;
}
//OPTION 5
if (choice == 5)
{
cout << "Please Enter The first integer: ";
cin >> numb1;
cout << "Please Enter The second integer: ";
cin >> numb2;
cout << "Please Enter The third integer: ";
cin >> numb3;
sum = numb1 * numb2;
if (sum > 0)
{cout << "Sum is greater than 0 "<<sum <<endl;}
if (numb3 > numb1)
{cout <<"numb3 is greater than numb1" << numb3<< endl;}
else if((sum>0) && (numb3 <numb1))
{cout <<"No test are true" <<endl;}
return 0;
}
if ((choice > 5) || (choice < 1))
{
cout << "\n\nERROR. PLEASE SELECT 1 - 5 ONLY.";
cout << "\n\n\n\nPress a key to return to selection menu...\n";
_getch();
goto start;
}
return 0;
}
int get_mid(int a,int b,int c)
{
if(a==b&&a==c)
return a;
if(a==b||a==c||b==c)
{
if(a==b)
return a;
if(a==c)
return a;
if(b==c)
return b;
}
if((a>b&&a<c)||(a<b&&a>c))
{
return a;
}
else if((b>a&&b<c)||(b<a&&b>c))
{
return b;
}
else return c;
}
int get_max(int a,int b,int c)
{
int tmpVar = (b>c)?b:c;
return (a>tmpVar)?a:tmpVar;
}
int get_min(int a,int b,int c)
{
int tmpVar = (b<c)?b:c;
return (a<tmpVar)?a:tmpVar;
}
|