Here be the code:
CODE
#include <stdio.h>
#include <math.h>
#define g_si 9.80665; //m/s^2 - global constants
#define g_us 32.1740; //f/s^2
float airdensity, tvelocity, drag, surfacearea, mass, k, dragchoice; // global variables
char quit;
void si();
void us(); //one will be SI, one will be US units;
void main() { //unit selection
int unit=0;
printf("This program will calculate the terminal velocity of an object on EARTH.\n\n\n\n");
printf("Select the corresponding number to the type of unit you wish to use:\n");
printf("1. SI Units\n");
printf("2. US Units\n");
scanf("%d", &unit);
if(unit=1) si(); // calls the corresponding function via user input
else us();
} // end MAIN function
void si() {
dragchoice = 0;
drag = 1; // a good base value would be 1, if it were 0 the terminal velocity would be undefined, meaning the slope would be a verticle line meaning there would be no terminal velocity meaning and it would accelerate until the end of time which is crazy...
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("First, we need to choose the object. Below are some basic categories.\n");
printf("Choose the corresponding number to the category that best suits your object,\n");
printf("and you will be supplied with a list of objects. Please, then, type in the coefficient of\n");
printf("drag exactly as it appears. This list will be updated as often as possible.\n\n\n");
// CATEGORIES LISTED BELOW
printf("1. Basic Shaped Objects, Miscellaneous (including sporting equipment)\n");
printf("2. Human Positions (including bicycle with a cyclist on it\n");
printf("3. Vehicles (general/specific vehicles included)\n");
printf("4. Enter your own coefficient of drag.\n");
scanf("%f", &dragchoice);
printf("\n\n\n\n\n");
if (dragchoice = 1) {
printf("BASIC SHAPED OBJECTS, MISCELLANEOUS\n\n");
printf("Cone (Air hitting pointy side)\t0.5\n");
printf("Cube (Air Hitting pointy side)\t0.8\n");
printf("Cube (Air Hitting straight side)\t1.05\n");
printf("Golf Ball\t0.3\n");
printf("Half-Sphere (Air hitting rounded side)\t0.42\n");
printf("Ping-Pong Ball\t0.5\n");
printf("Smooth Brick\t2.1\n");
printf("Sphere\t0.47\n");
printf("Tennis Ball\t0.3\n");
printf("Very Large Man, Upright Position\t1.3\n");
printf("To go back to main menu, type 0. Otherwise type in the coefficient.\n");
scanf("%f", &drag);
if (drag = 0) {
si(); // if the user fucked up, they type 0 and it sends them to the si() { function (the beginning of SI)
} // end SI if
} // end if
else if (dragchoice = 2) {
printf("HUMAN POSITIONS\n\n");
printf("Large Man, Upright Position\t1.2\n");
printf("Medium Sized Man, Upright Position\t1.1\n");
printf("Parachutist, Speed Position\t1.05\n");
printf("Parachutist, Sprawled Out\t1.35\n");
printf("Parachutist, Straight Position\t1.25\n");
printf("Ski Jumper1.25\n");
printf("Skier\t1.05\n");
printf("Small Man, Upright Position\t1.0\n");
printf("Typical Bicycle w/Cyclist\t0.9\n");
printf("To go back to main menu, type 0. Otherwise type in the coefficient.\n");
scanf("%f", &drag);
if (drag = 0) {
si();
}
} // end else if
else if (dragchoice = 3) {
printf("VEHICLES (SPECIFIC AND GENERAL\n\n");
printf("Standard Economy Car\t0.45\n");
printf("Standard Pickup Truck\t0.5\n");
printf("Standard Medium Sized Truck (Larger than pickup)\t0.8\n");
printf("Standard Sports Car\t0.35\n");
printf("Audi 100, 1983\t0.3\n");
printf("Audi A3, 2006\t0.33\n");
printf("BMW 8-Series, 1989\t0.29\n");
printf("Chevrolet Camaro, 1995\t0.338\n");
printf("Chevrolet Caprice, 1994-1996\t0.34\n");
printf("Citroën 2CV\t0.51\n");
printf("Citroën CX, 1974\t0.36\n");
printf("Citroën DS, 1955\t0.36\n");
printf("Citroën GSA, 1980\t0.31\n");
printf("Dodge Charger, 2006\t0.33\n");
printf("Dodge Durango, 2004\t0.39\n");
printf("Ferrari F40, 1987\t0.34\n");
printf("Ferrari F50, 1996\t0.372\n");
printf("Ferrari Testarossa, 1986\t0.36\n");
printf("Please type 0 if you want to go to the next page.\n");
scanf("%f", &drag);
if (drag = 0) {
drag = 1;
printf("Ford Probe V prototype, 1985\t0.137\n");
printf("Ford Sierra, 1982\t0.34\n");
printf("General Motors EV1, 1996\t0.195\n");
printf("Honda Accord Hybrid, 2005\t0.29\n");
printf("Honda Insight, 1999\t0.25\n");
printf("Hummer H2, 2003\t0.57\n");
printf("Infiniti G35, 2002\t0.27\n");
printf("Lamborghini Countach, 1974\t0.42\n");
printf("Lotus Elite, 1958\t0.29\n");
printf("Mercedes-Benz 'Bionic Car' Concept, 2005 0.19\n");
printf("Porsche 996, 1997\t0.3\n");
printf("Porsche 997, 2004\t0.28\n");
printf("Porsche Boxster, 2005\t0.29\n");
printf("Saab 92, 1947\t0.3\n");
printf("Subaru Impreza WRX STi, 2004\t0.33\n");
printf("Tatra T77, 1938\t0.212\n");
printf("Toyota Camry or Lexus ES, 2005\t0.28\n");
printf("Toyota Celica,1995-2005\t0.32\n");
printf("Toyota Prius, 2004\t0.26\n");
printf("Volkswagen Beetle\t0.38\n");
printf("To go back to main menu, type 0. Otherwise type in the coefficient.\n");
scanf("%f", &drag);
if (drag = 0) {
si();
}
}
}
else if (dragchoice = 4) {
drag = 1;
printf("Enter in the drag coefficient you wish to use: ");
scanf("%f", &drag);
if (drag = 0) {
si();
}
}
else {
printf("Error, please retry.\n");
si();
}
} // end SI function
void us() {
dragchoice = 0;
drag = 1; // a good base value would be 1, if it were 0 the terminal velocity would be undefined, meaning the slope would be a verticle line meaning there would be no terminal velocity meaning and it would accelerate until the end of time which is crazy...
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("First, we need to choose the object. Below are some basic categories.\n");
printf("Choose the corresponding number to the category that best suits your object,\n");
printf("and you will be supplied with a list of objects. Please, then, type in the coefficient of\n");
printf("drag exactly as it appears. This list will be updated as often as possible.\n\n\n");
// CATEGORIES LISTED BELOW
printf("1. Basic Shaped Objects, Miscellaneous (including sporting equipment)\n");
printf("2. Human Positions (including bicycle with a cyclist on it\n");
printf("3. Vehicles (general/specific vehicles included)\n");
printf("4. Enter your own coefficient of drag.\n");
scanf("%f", &dragchoice);
printf("\n\n\n\n\n\n");
if (dragchoice = 1) {
printf("BASIC SHAPED OBJECTS, MISCELLANEOUS\n\n");
printf("Cone (Air hitting pointy side)\t0.5\n");
printf("Cube (Air Hitting pointy side)\t0.8\n");
printf("Cube (Air Hitting straight side)\t1.05\n");
printf("Golf Ball\t0.3\n");
printf("Half-Sphere (Air hitting rounded side)\t0.42\n");
printf("Ping-Pong Ball\t0.5\n");
printf("Smooth Brick\t2.1\n");
printf("Sphere\t0.47\n");
printf("Tennis Ball\t0.3\n");
printf("Very Large Man, Upright Position\t1.3\n");
printf("To go back to main menu, type 0. Otherwise type in the coefficient.\n");
scanf("%f", &drag);
if (drag = 0) {
us(); // if the user fucked up, they type 0 and it sends them to the si() { function (the beginning of SI)
} // end SI if
} // end if
else if (dragchoice = 2) {
printf("HUMAN POSITIONS\n\n");
printf("Large Man, Upright Position\t1.2\n");
printf("Medium Sized Man, Upright Position\t1.1\n");
printf("Parachutist, Speed Position\t1.05\n");
printf("Parachutist, Sprawled Out\t1.35\n");
printf("Parachutist, Straight Position\t1.25\n");
printf("Ski Jumper1.25\n");
printf("Skier\t1.05\n");
printf("Small Man, Upright Position\t1.0\n");
printf("Typical Bicycle w/Cyclist\t0.9\n");
printf("To go back to main menu, type 0. Otherwise type in the coefficient.\n");
scanf("%f", &drag);
if (drag = 0) {
us();
}
} // end 2nd else if
else if (dragchoice=3) {
printf("VEHICLES (SPECIFIC AND GENERAL\n\n");
printf("Standard Economy Car\t0.45\n");
printf("Standard Pickup Truck\t0.5\n");
printf("Standard Medium Sized Truck (Larger than pickup)\t0.8\n");
printf("Standard Sports Car\t0.35\n");
printf("Audi 100, 1983\t0.3\n");
printf("Audi A3, 2006\t0.33\n");
printf("BMW 8-Series, 1989\t0.29\n");
printf("Chevrolet Camaro, 1995\t0.338\n");
printf("Chevrolet Caprice, 1994-1996\t0.34\n");
printf("Citroën 2CV\t0.51\n");
printf("Citroën CX, 1974\t0.36\n");
printf("Citroën DS, 1955\t0.36\n");
printf("Citroën GSA, 1980\t0.31\n");
printf("Dodge Charger, 2006\t0.33\n");
printf("Dodge Durango, 2004\t0.39\n");
printf("Ferrari F40, 1987\t0.34\n");
printf("Ferrari F50, 1996\t0.372\n");
printf("Ferrari Testarossa, 1986\t0.36\n");
printf("Please type 0 if you want to go to the next page.\n");
scanf("%f", &drag);
if (drag = 0) {
drag = 1;
printf("Ford Probe V prototype, 1985\t0.137\n");
printf("Ford Sierra, 1982\t0.34\n");
printf("General Motors EV1, 1996\t0.195\n");
printf("Honda Accord Hybrid, 2005\t0.29\n");
printf("Honda Insight, 1999\t0.25\n");
printf("Hummer H2, 2003\t0.57\n");
printf("Infiniti G35, 2002\t0.27\n");
printf("Lamborghini Countach, 1974\t0.42\n");
printf("Lotus Elite, 1958\t0.29\n");
printf("Mercedes-Benz 'Bionic Car' Concept, 2005 0.19\n");
printf("Porsche 996, 1997\t0.3\n");
printf("Porsche 997, 2004\t0.28\n");
printf("Porsche Boxster, 2005\t0.29\n");
printf("Saab 92, 1947\t0.3\n");
printf("Subaru Impreza WRX STi, 2004\t0.33\n");
printf("Tatra T77, 1938\t0.212\n");
printf("Toyota Camry or Lexus ES, 2005\t0.28\n");
printf("Toyota Celica,1995-2005\t0.32\n");
printf("Toyota Prius, 2004\t0.26\n");
printf("Volkswagen Beetle\t0.38\n");
printf("To go back to main menu, type 0. Otherwise type in the coefficient.\n");
scanf("%f", &drag);
if (drag = 0) {
us();
}
}
}
else if (dragchoice = 4) {
drag = 1;
printf("Enter in the drag coefficient you wish to use: ");
scanf("%f", &drag);
if (drag = 0) {
us();
}
}
else {
printf("Error, please retry.\n");
us();
}
} // end US function
Problem #1: I'm sure it's something stupidly simple that I'm overlooking but when I run it and choose a unit of measurement, once I input my specific dragchoice to open up the larger menu of options, it ALWAYS goes to dragchoice #1 (Basic shapes).
Problem #2: In any of those if commands, I put the code
CODE
if (drag = 0) {
us();
}
I assume that if they type in 0 for that drag, it would restart that function all over again but for some reason it doesn't. However since problem #1 states that there is a huge problem with my if statements, I assume it could be in there as well.
Overall, I can't enter in any dragchoice, it is ignoring the user and secondly it is not letting me go back to the main menu by typing 0.
Thanks.