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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
|
#include <iostream>
#include <cctype>
#include <stdlib.h>
#include <math.h>
using namespace std;
//prototypes go here
char displayMenu_01();
char displayMenu_02();
void Get_x_and_y();
void Add_2_Numbers();
void Subtract_2_Numbers();
void Multiply_2_Numbers();
void Divide_2_Numbers();
void Square_A_Number();
void Cube_A_Number();
void Raise_to_any_power();
void Square_root_a_number();
void Cube_root_a_number();
void Take_any_Root();
float x, y, sum;
int main() // This function is used to call other functions.
{
char choice;
bool test = true;
while (test)
{
choice = displayMenu_01();
switch (choice)
{
case 'a': Add_2_Numbers();
break;
case 'b': Subtract_2_Numbers();
break;
case 'c': Divide_2_Numbers();
break;
case 'd': Multiply_2_Numbers();
break;
case 'e':
if (displayMenu_02() == 'q') test = false;
break;
case 'q': //Exit_the_program
test = false;
break;
}
}
cout << "Thanks For Using calculator"<< endl;
return 0;
}
char displayMenu_01()
{
char choice;
{
cout
<< " \n Hello, and welcome to the Calculator Practice Program."
<< " This program allows you to practice your math skills."
<< "Choose what you want to practice in the menu shown below.\n\n"
<< " (a) Addition\n"
<< " (b) Subtraction\n"
<< " (c) Division\n"
<< " (d) Mulpilication\n"
<< " (e) Powers & Roots\n"
<< " (q) Exit\n\n"
<< " Enter Your Choice[a-e,q ]: ";
cin >> choice;
//return choice;
}
// We now have the user's input in "choice".
// We are going to analyze the input with decision logic.
choice = tolower(choice);
if (choice >= 'a' && choice <= 'e' || choice == 'q')
cout << "You entered: '" << choice << "', that is correct input. " << endl;
else
{
cout << "You did not enter 'a', 'b', 'c', 'e' or 'q'" << endl;
//cout << "Please rerun the program." << endl;
}
cout << endl;
return choice;
}
char displayMenu_02()
{
char choice;
{
//char choice;
bool test = true;
while (test)
{
cout
<< "---------------------------------------------------\n"
<< "POWERS & ROOTS MENU\n"
<< "---------------------------------------------------\n"
<< "a. Square a number (Xˆ2)\n"
<< "b. Cube a number (Xˆ3)\n"
<< "c. Raise to any power (XˆY)\n"
<< "d. Square root a number (Xˆ1/2)\n"
<< "e. Cube root a number (Xˆ1/3)\n"
<< "f. Take any root (Xˆ1/Y)\n"
<< "m. Return to Main Menu\n"
<< "q. Quit the program\n"
<< "---------------------------------------------------\n"
<< "Enter your choice [ a - f, m, q ]:\n"
<< "---------------------------------------------------\n";
cin >> choice;
switch (choice)
{
case 'a': Square_A_Number();
break;
case 'b': Cube_A_Number();
break;
case 'c': Raise_to_any_power();
break;
case 'd': Square_root_a_number();
break;
case 'e': Cube_root_a_number();
break;
case 'f': Take_any_Root();
break;
case 'm':
if (choice == 'm' || 'q') test = false; // m returns to main menu
break;
case 'q':
test = false; // quits the program.
break;
}
}
}
return choice;
}
void Get_x_and_y()
{
char choice;
cout << "Will this be an Integer or floating point? " << endl;
cout << "i for int " << endl;
cout << "f for float" << endl;
cin >> choice;
choice = tolower(choice);
switch (choice)
{
case 'i': cout << "Input values for x and y" << endl;
cin >> x >> y;
x = (int)x;
y = (int)y;
break;
case 'f': cout << "input values for x and y"<< endl;
cin >> x >> y;
break;
default: cout << "Input is incorrect, Please try again" << endl;
break;
}
/*cout << "Please input x and y: ";
cin >> x;
cin >> y;
*/
}
void Add_2_Numbers()
{
//int x, y, sum; //first try it with "int"
//float x, y, sum;//next try it with "float"
cout << "This program will add x and y ..." << endl;
cout << endl << endl;
Get_x_and_y();
sum = x + y;
cout << endl << endl;
cout << " x + y = " << x << " + " << y
<< " = " << sum << endl;
}
void Subtract_2_Numbers()
{
//int x, y, sum; //first try it with "int"
float x, y, subtract; //next try it with "float"
cout << "This program will subtract, x and y ..." << endl;
cout << endl << endl;
cout << "Please input x and y: ";
cin >> x;
cin >> y;
subtract = x - y;
cout << endl << endl;
cout << " x - y = " << x << " - " << y
<< " = " << subtract << endl;
}
void Multiply_2_Numbers()
{
//int x, y, sum; //first try it with "int"
float x, y, Multiply; //next try it with "float"
cout << "This program will subtract, x and y ..." << endl;
cout << endl << endl;
cout << "Please input x and y: ";
cin >> x;
cin >> y;
Multiply = x * y;
cout << endl << endl;
cout << " x * y = " << x << " * " << y
<< " = " << Multiply << endl;
}
{
//int x, y, sum; //first try it with "int"
float x, y, Division; //next try it with "float"
cout << "This program will subtract, x and y ..." << endl;
cout << endl << endl;
cout << "Please input x and y: ";
cin >> x;
cin >> y;
Division = x / y;
cout << endl << endl;
cout << " x / y = " << x << " / " << y
<< " = " << Division << endl;
}
void Square_A_Number()
{
float x, Square;
cout << "This program will Square x.." << endl;
cout << endl << endl;
cout << "Please input x.... ";
cin >> x ;
Square = pow(x, 2.0);
cout << endl << endl;
cout << Square << endl;
}
void Cube_A_Number()
{
float x, Cube;
cout << "This program will Cube x.." << endl;
cout << endl << endl;
cout << "Please input x.... ";
cin >> x ;
Cube = pow(x, 3.0);
cout << endl << endl;
cout << Cube << endl;
}
void Raise_to_any_power()
{
float x, y, Power;
cout << "This program will raise x to any power.." << endl;
cout << endl << endl;
cout << "Please input x and y.... ";
cin >> x;
cin >> y;
Power = pow(x, y);
cout << endl << endl;
cout << Power << endl;
}
void Square_root_a_number()
{
float x, Sqr_Root;
cout << "This program will take the square root of a number.." << endl;
cout << endl << endl;
cout << "Please input x.... ";
cin >> x;
Sqr_Root = pow(x, 1.0 / 2.0);
cout << endl << endl;
cout << Sqr_Root << endl;
}
void Cube_root_a_number()
{
float x, Cube_root;
cout << "This program will take the cube root of a number.." << endl;
cout << endl << endl;
cout << "Please input x.... ";
cin >> x;
Cube_root = pow(x, 1.0 / 3.0);
cout << endl << endl;
cout << Cube_root << endl;
}
void Take_any_Root()
{
float x, Root;
cout << "This program will take the cube root of a number.." << endl;
cout << endl << endl;
cout << "Please Input x and y.... ";
cin >> x;
cin >> y;
Root = pow(x, 1.0 / y);
cout << endl << endl;
cout << Root << endl;
}
}
}
|