// Solar Car Debug // solar_car.c // // This program was written by (zXXXXXXX) // on // // This program should scan in information about a solar car including it's // mode, speed and the distances between chargers that it has travelled // and print out the solar car's information to the terminal. #include enum state { DRIVE, SOLAR, OFF, MAINTENANCE_MODE, CRUISE_MODE }; struct car { enum state state; double speed; int distance; }; int main(void) { int state; struct solar_car; printf("What mode is the car in (DRIVE = 0, SOLAR = 1, OFF = 2, MAINTENANCE_MODE = 3, CRUISE_MODE = 4)? "); scanf("%d", state); if (state = 0) { solar_car.state = DRIVE; } else if (state = 1) { solar_car.state = SOLAR; } else if (state = 2){ solar_car.state = OFF; } else if (state = 3) { solar_car.state = MAINTENANCE_MODE; } else { solar_car.state = CRUISE_MODE; } printf("What speed is the car going? "); scanf("%d", &solar_car.speed); if (solar_car.state == MAINTENANCE_MODE && solar_car.state == OFF) { printf("No no silly, the speed is 0\n"); solar_car.speed = 0; } printf("Please enter the 5 distances between the chargers that the car has traveled? "); int i = 0; int sum = 0; solar_car.distance; while (i < 5) { scanf("%d", &sum); solar_car.distance = solar_car.distance + sum; } printf("Solar Car Information:\n"); printf("Speed: %.2lf\n", solar_car.speed); printf("Distance travelled: %d\n", solar_car.distance); printf("State: "); if (solar_car.state == DRIVE) { printf("DRIVE\n"); } else if (solar_car.state == SOLAR){ printf("SOLAR\n"); } else if (solar_car.state == OFF) { printf("OFF\n"); } else if (solar_car.state == MAINTENANCE_MODE){ printf("MAINTENANCE_MODE\n"); } else { printf("CRUISE_MODE\n"); } return 0; }