#include <iostream>
#include <math.h>
usingnamespace std;
int One;
int Two;
int Three;
int choose;
void conversion() {
cout << " MENU \n";
cout << " 1. Currency \n";
cout << " 2. Temperature \n";
cin >> choose;
if (choose == 1) {
switch (choose) {
case 1:
cout << " 1. British Stirling to Euro \n";
cout << " 2. British Stirling to US Dollars \n";
cout << " 3. British Stirling to Canadian Dollars \n";
cout << " 4. British Stirling to Australian Dollars \n";
cout << " 5. British Stirling to Japanese Yen \n";
cout << " 6. British Stirling to Indian Rupees \n";
cout << " 7. British Stirling to Chinese Renminbi \n";
cout << " 8. Vise versa \n";
}
cin >> choose;
if (choose == 1) {
cout << "Enter the British Stirling to convert into Euros \n";
cin >> choose;
cout << choose * 1.14;
}
if (choose == 2) {
cout << "Enter the British Stirling to convert into US Dollars \n";
cin >> choose;
cout << choose * 1.62;
}
if (choose == 3) {
cout << "Enter the British Stirling to convert into Canadian Dollars \n";
cin >> choose;
cout << choose * 1.74;
}
if (choose == 4) {
cout << "Enter the British Stirling to convert into Australian Dollars \n";
cin >> choose;
cout << choose * 1.87;
}
if (choose == 5) {
cout << "Enter the British Stirling to convert into Japanese Yen \n";
cin >> choose;
cout << choose * 148.67;
}
if (choose == 6) {
cout << "Indian Rupees \n";
cin >> choose;
cout << choose * 78.31;
}
if (choose == 7) {
cout << "Chinese Renminbi \n";
cin >> choose;
cout << choose * 11.11;
}
if (choose == 8) {
cout << " 1. Euro to British Stirling \n";
cout << " 2. US Dollars to British Stirling \n";
cout << " 3. Canadian Dollars to British Stirling \n";
cout << " 4. Australian Dollars to British Stirling \n";
cout << " 5. Japanese Yen to British Stirling \n";
cout << " 6. Indian Rupees to British Stirling \n";
cout << " 7. Chinese Renminbi to British Stirling \n";
}
switch (choose) {
case 1:
cout << "Please enter the Euros to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.90;
break;
case 2:
cout << "Please enter the US Dollars to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.61;
break;
case 3:
cout << "Please enter the Canadian Dollars to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.57;
break;
case 4:
cout << "Please enter the Australian Dollars to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.53;
break;
case 5:
cout << "Please enter the Japanese Yen to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.0067;
break;
case 6:
cout << "Please enter the Chinese Renminbi to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.09;
break;
}
}
if (choose == 2) {
cout << " 1. Celcius to Farenheit \n";
cout << " 2. Farenheit to Celcius \n";
cin >> choose;
}
if (choose == 1) {
cout << "Please enter the celcius to convert to farenheit \n";
cin >> choose;
cout << choose * 1.8 + 32;
}
if (choose == 2) {
cout << "Please enter the farenheit to convert to celcius \n";
cin >> choose;
cout << (choose - 32) / 1.8;
}
}
void area() {
cout << " MENU \n";
cout << " 1. Area of a triangle \n";
cout << " 2. Area of a square \n";
cout << " 3. Area of a rectangle \n";
cout << " 4. Area of a circle \n";
cout << " 5. Area of a trapezium \n";
cin >> choose;
switch (choose) {
case 1:
cout << "Please enter the base length of the triangle, followed by the height. ";
cin >> One >> Two;
cout << "The area of the triangle is " << One / 2 * Two << " " ;
break;
case 2:
cout << "Please enter the length of one of the sides of the square please. ";
cin >> One;
cout << "The area of the square is " << One * One << " " ;
break;
case 3:
cout << "Please enter the length of the rectangle, followed by the height. ";
cin >> One >> Two;
if (One == Two) {
cout << "Thats not the dimensions of a rectangle! They have to be different! ";
area();
}
else {
cout << "The area of the rectangle is " << One * Two << " " ;
break;
}
case 4:
Two = 3.14;
cout << "Please enter the radius of the cirlce please. ";
cin >> One;
cout << "The area of the cirlce is " << Two * One * One << " " ;
break;
case 5:
cout << "Please enter the length of the 2 parrallel sides and also the height. ";
cin >> One >> Two >> Three;
cout << "The area of the trapezium is " << (One + Two) * 0.5 * Three << " ";
break;
}
}
void powers() {
float power;
cout << " MENU \n";
cout << " 1. Powers \n";
cout << " 2. Square roots \n";
cin >> choose;
if (choose == 1) {
cout << "Please enter the number you would like to square and the number of times you would like to times it by it. ";
cin >> One >> Two;
cout << "\t" << pow(One, Two) << " " ;
}
if (choose == 2) {
cout << "Enter a number to find its square route. ";
cin >> power;
cout << "\t" << sqrt(power) << " " ;
}
}
void division() {
cin >> One >> Two;
cout << "\t" << One / Two << " " ;
}
void multiplication() {
cin >> One >> Two;
cout << "\t" << One * Two << " " ;
}
void addition() {
cin >> One >> Two;
cout << "\t" << One + Two << " " ;
}
void subtraction() {
cin >> One >> Two;
cout << "\t" << One - Two << " " ;
}
int main () {
system ("clear");
cout << " MENU \n";
cout << " 1. Subtraction\n";
cout << " 2. Addition\n";
cout << " 3. Multiplication\n";
cout << " 4. Division\n";
cout << " 5. Powers\n";
cout << " 6. Areas\n";
cout << " 7. Conversions\n";
cout << " 8. Quit\n";
cin >> choose;
switch (choose) {
case 1:
subtraction();
break;
case 2:
addition();
break;
case 3:
multiplication();
break;
case 4:
division();
break;
case 5:
powers();
break;
case 6:
area();
break;
case 7:
conversion();
break;
case 8:
break;
}
return 0;
}
void conversion() {
cout << " MENU \n";
cout << " 1. Currency \n";
cout << " 2. Temperature \n";
cin >> choose;
if (choose == 1) {
switch (choose) {
case 1:
cout << " 1. British Stirling to Euro \n";
cout << " 2. British Stirling to US Dollars \n";
cout << " 3. British Stirling to Canadian Dollars \n";
cout << " 4. British Stirling to Australian Dollars \n";
cout << " 5. British Stirling to Japanese Yen \n";
cout << " 6. British Stirling to Indian Rupees \n";
cout << " 7. British Stirling to Chinese Renminbi \n";
cout << " 8. Vise versa \n";
}
cin >> choose;
if (choose == 1) {
cout << "Enter the British Stirling to convert into Euros \n";
cin >> choose;
cout << choose * 1.14;
}
if (choose == 2) {
cout << "Enter the British Stirling to convert into US Dollars \n";
cin >> choose;
cout << choose * 1.62;
}
if (choose == 3) {
cout << "Enter the British Stirling to convert into Canadian Dollars \n";
cin >> choose;
cout << choose * 1.74;
}
if (choose == 4) {
cout << "Enter the British Stirling to convert into Australian Dollars \n";
cin >> choose;
cout << choose * 1.87;
}
if (choose == 5) {
cout << "Enter the British Stirling to convert into Japanese Yen \n";
cin >> choose;
cout << choose * 148.67;
}
if (choose == 6) {
cout << "Indian Rupees \n";
cin >> choose;
cout << choose * 78.31;
}
if (choose == 7) {
cout << "Chinese Renminbi \n";
cin >> choose;
cout << choose * 11.11;
}
if (choose == 8) {
cout << " 1. Euro to British Stirling \n";
cout << " 2. US Dollars to British Stirling \n";
cout << " 3. Canadian Dollars to British Stirling \n";
cout << " 4. Australian Dollars to British Stirling \n";
cout << " 5. Japanese Yen to British Stirling \n";
cout << " 6. Indian Rupees to British Stirling \n";
cout << " 7. Chinese Renminbi to British Stirling \n";
}
switch (choose) {
case 1:
cout << "Please enter the Euros to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.90;
break;
case 2:
cout << "Please enter the US Dollars to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.61;
break;
case 3:
cout << "Please enter the Canadian Dollars to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.57;
break;
case 4:
cout << "Please enter the Australian Dollars to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.53;
break;
case 5:
cout << "Please enter the Japanese Yen to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.0067;
break;
case 6:
cout << "Please enter the Chinese Renminbi to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.09;
break;
}
}
if (choose == 2) {
cout << " 1. Celcius to Farenheit \n";
cout << " 2. Farenheit to Celcius \n";
cin >> choose;
}
if (choose == 1) {
cout << "Please enter the celcius to convert to farenheit \n";
cin >> choose;
cout << choose * 1.8 + 32;
}
if (choose == 2) {
cout << "Please enter the farenheit to convert to celcius \n";
cin >> choose;
cout << (choose - 32) / 1.8;
}
}
Lets say the user selects British Stirling to Euro \n"; then choose will be 1 (line 25)
The user enter 2 British sterling to be converted - Now choose == 2 (line 28).
Now choose is checked on line 32 and the user will be asked "Enter the British Stirling to convert into US Dollars \n"
Lets say that the user enters 2 again.
Now choose is checked at line 92 - choose is 2 - so the user will be asked for << "Please enter the US Dollars to convert to British Stirling \n" (Line 99)
Lets say the user asks for 1 US Dollar to be converted - choose ==1 (line 100).
Now choose is checked again (Line 136) and will ask cout << "Please enter the celcius to convert to farenheit \n";
As I'm sure you're aware, you use the variable "choose" for just about everything to drive your menu selection. Perhaps as an afterthought you may want to place some inline comments to help any other programmer reading your code as to what you expect the value of choose to do after you have read it in. This is what I mean:
if (choose == 8) {
cout << " 1. Euro to British Stirling \n";
cout << " 2. US Dollars to British Stirling \n";
cout << " 3. Canadian Dollars to British Stirling \n";
cout << " 4. Australian Dollars to British Stirling \n";
cout << " 5. Japanese Yen to British Stirling \n";
cout << " 6. Indian Rupees to British Stirling \n";
cout << " 7. Chinese Renminbi to British Stirling \n";
}
switch (choose) {
case 1:
cout << "Please enter the Euros to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.90;
break;
case 2:
cout << "Please enter the US Dollars to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.61;
break;
case 3:
cout << "Please enter the Canadian Dollars to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.57;
break;
case 4:
cout << "Please enter the Australian Dollars to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.53;
break;
case 5:
cout << "Please enter the Japanese Yen to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.0067;
break;
case 6:
cout << "Please enter the Chinese Renminbi to convert to British Stirling \n";
cin >> choose;
cout << choose * 0.09;
break;
}
}
if (choose == 2) {
cout << " 1. Celcius to Farenheit \n";
cout << " 2. Farenheit to Celcius \n";
cin >> choose;
}
if (choose == 1) {
cout << "Please enter the celcius to convert to farenheit \n";
cin >> choose;
cout << choose * 1.8 + 32;
}
if (choose == 2) {
cout << "Please enter the farenheit to convert to celcius \n";
cin >> choose;
cout << (choose - 32) / 1.8;
}
Okay, from your menu, I am supposed to be able to select 7. There is no outcome for choose ==7 in your switch. Also for these last few if blocks, I'd have to keep following you through your switch to even figure out what is going on at the end. Just some //inline comments would be snazzy here.
Also I note that you do not have a default switch statement. The user could easily break your code by typing a char or string instead of an integer. Possibly using a try/catch on your cin statements could be another option.
Also I noticed in your conversion() function that you start out by writing a switch statement with only one outcome, and then proceed to use if statements if(choose ==1)...if(choose ==2) for a large number of other outcomes. This doesnt make much sense to me, I would think you'd put this the other way around. If you just want it to print that menu, perhaps a do{ }while(choose != 0) or whatever you want the exit integer to be. There should be some way for the user to enter a function and then decide they dont want to proceed and return to previous menu at EVERY step in your program.
Your code is still very poorly constructed. You should really take all the input in your main function and pass it through to your functions, which should then return the result to be output in your main function. There's also absolutely no need for any global variables.
And in C++ you should be including <cmath> rather than <math.h>.