#include #include #include #include #include int main() { while (true) { srand(time(0)); printf("Train\n"); printf("Creative Computing Morristown, New Jersey\n"); printf("Time - Speed Distance Exercise:"); int car = (rand() %(65-40+1))+40; int distance = (rand() %(20-5+1))+5; int train = (rand() %(39-20+1))+20; printf(" A car traveling %d MPH can make a certain trip in %d hours less than a train traveling at %d MPH.\n", car, distance, train); while (true) { char input[5]; printf("\nHow long does a trip take by car "); fgets(input, 5, stdin); double answer = atof(input); int car_time = distance * train / (car - train); int percent = abs(((car_time)-answer)*100/answer)+.5; if (percent > 5) { printf("Sorry, you were off by %d percent\n", percent); printf("Correct answer is %d hours\n", car_time); } else { printf("Good!, Answer within %d percent\n", percent); printf("Another Problem? (yes or no)"); char newgame[5]; fgets(newgame, 5,stdin); if (strcmp("yes", newgame)) { break; } return 1; } continue; } } }