CODING
CODING
h>
#include <stdlib.h>
#include <math.h>
void clearScreen(void) {
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
int main(void) {
// declare variables
int n, p, x, y, z;
float V, I, R, P, Current, Voltage, Power, Resistance;
float F, C, Fahrenheit, Celsius, Rankine, radius, areacir, l, h, arearec;
float base, areatri, a, b, areaell;
int i;
// start screen
START:
clearScreen(); //system("cls");
printf("\n\nWELCOME to Basic Engineering Formulas");
printf("\n Type 1 for Electrical Formulas");
printf("\n Type 2 for Temperature Conversion");
printf("\n Type 3 for Area of Shapes");
printf("\n Type 4 to Exit");
printf("\nEnter your choice: ");
scanf("%d", &n);
switch (n) {
case 1:
printf("\n Welcome to the Current Formula!");
printf("\n Enter voltage in V: ");
scanf("%f", &V);
printf("\n Enter resistance in ohms: ");
scanf("%f", &R);
Current = (V / R);
printf("\n The current is %f A", Current);
goto START;
break;
case 2:
printf("\n Welcome to the Voltage Formula!");
printf("\n Enter current in A: ");
scanf("%f", &I);
printf("\n Enter resistance in ohms: ");
scanf("%f", &R);
Voltage = (I * R);
printf("\n The voltage is %f V", Voltage);
goto START;
break;
case 3:
printf("\n Welcome to the Power Formula!");
printf("\n Enter current in A: ");
scanf("%f", &I);
printf("\n Enter voltage in V: ");
scanf("%f", &V);
Power = (I * V);
printf("\n The power is %f", Power);
goto START;
break;
case 4:
printf("\n Welcome to the Resistance Formula!");
printf("\n Enter current in A: ");
scanf("%f", &I);
printf("\n Enter voltage in V: ");
scanf("%f", &V);
Resistance = (V / I);
printf("\n The resistance is %f ohms", Resistance);
goto START;
break;
//exit
case 5:
return 0;
break;
//return to start
case 6:
goto START; //GOTO
break;
default:
printf("\nError");
goto START;
break;
}
break;
// TEMPERATURE
case 2: //n
printf("\n Welcome to Temperature Conversion!");
printf("\n Type 1 for Celsius to Fahrenheit");
printf("\n Type 2 for Fahrenheit to Celsius");
printf("\n Type 3 for Celsius to Rankine");
printf("\n Type 4 for Fahrenheit to Rankine");
printf("\n Type 5 to Exit");
printf("\n Type 6 to Return");
printf("\n Enter your choice: ");
scanf("%d", &y);
switch (y) {
case 1:
printf("\n Welcome to Celsius to Fahrenheit Conversion!");
printf("\n Enter temperature in celsius: ");
scanf("%f", &C);
Fahrenheit = ((1.8 * C) + 32);
printf("\n The temperature is %f Fahrenheit", Fahrenheit);
goto START;
break;
case 2:
printf("\n Welcome to Fahrenheit to Celsius Conversion!");
printf("\n Enter temperature in fahrenheit: ");
scanf("%f", &F);
Celsius = (0.55555556 * (F - 32));
printf("\n The temperature is %f Celsius", Celsius);
goto START;
break;
case 3:
printf("\n Welcome to Celsius to Rankine Conversion!");
printf("\n Enter temperature in celsius: ");
scanf("%f", &C);
Rankine = ((1.8 * C + 32) + 459.69);
printf("\n The temperature is %f Rankine", Rankine);
goto START;
break;
case 4:
printf("\n Welcome to Fahrenheit to Rankine Conversion!");
printf("\n Enter temperature in fahrenheit: ");
scanf("%f", &F);
Rankine = (F + 459.69);
printf("\n The temperature is %f Rankine", Rankine);
goto START;
break;
case 5:
return 0;
break;
case 6:
goto START;
break;
default:
printf("\nError");
goto START;
break;
}
break;
// AREA
case 3:
printf("\n Welcome to Area of Shapes!");
printf("\n Type 1 for Circle");
printf("\n Type 2 for Rectangle");
printf("\n Type 3 for Triangle");
printf("\n Type 4 for Ellipse");
printf("\n Type 5 to Exit");
printf("\n Type 6 to Return");
printf("\n Enter your choice: ");
scanf("%d", &z);
switch (z) {
case 1:
printf("\n Welcome to the Area of Circle Formula!");
printf("\n Enter radius: ");
scanf("%f", &radius);
areacir = (3.14 * radius * radius);
printf("\n The area is %f", areacir);
goto START;
break;
case 2:
printf("\n Welcome to the Area of Rectangle Formula!");
printf("\n Enter length: ");
scanf("%f", &l);
printf("\n Enter height: ");
scanf("%f", &h);
arearec = (l * h);
printf("\n The area is %f", arearec);
goto START;
break;
case 3:
printf("\n Welcome to the Area of Triangle Formula!");
printf("\n Enter base length: ");
scanf("%f", &base);
printf("\n Enter height: ");
scanf("%f", &h);
areatri = (0.5 * base * h);
printf("\n The area is %f", areatri);
goto START;
break;
case 4:
printf("\n Welcome to the Area of Ellipse Formula!");
printf("\n Enter a height: ");
scanf("%f", &a);
printf("\n Enter b length: ");
scanf("%f", &b);
areaell = (3.14 * a * b);
printf("\n The area is %f", areaell);
goto START;
break;
case 5:
return 0;
break;
case 6:
goto START;
break;
default:
printf("\nError");
goto START;
break;
}
break;
// EXIT
case 4:
return 0;
break;
// ERROR
default:
printf("\nError");
goto START;
break;
}
return 0;
}