#include #include #include #include #include "main.h" #include "fuel.h" #include "help.h" #include "test_src.h" #include "verify_indata.h" int main (int argc, char* argv[]) { /* PARAMETERS */ const int correct_num_params = 3; /* OPTIONS */ /* short options */ char* shrt_opts = "htv"; /* long options */ struct option const long_options[] = { {"help", no_argument, NULL, 'h'}, {"test", no_argument, NULL, 't'}, {"version", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0} }; /* modes */ _Bool help_mode; _Bool test_mode; _Bool version_mode; /* parse options and arguments */ int oi; // TODO: what do you need this for? int o; int oc = 0; while (true) { oi = -1; o = getopt_long(argc, argv, shrt_opts, long_options, &oi); if (o == -1) { break; } else { oc++; } switch (o) { case 'h': help_mode = true; break; case 't': test_mode = true; break; case 'v': version_mode = true; break; default: indata_error(); }; } if (help_mode) { help(); } if (test_mode) { test_src(); } if (version_mode) { version(); } /* verify correct number of parameters */ number_of_params(argc, oc, correct_num_params); // check_arg_types(); // TODO /* get user indata */ int miles_one_year_ago = atoi(argv[oc + 1]); int miles_today = atoi(argv[oc + 2]); int liters = atoi(argv[oc + 3]); sensible_indata(miles_one_year_ago, miles_today, liters); /* all systems ready, do compute */ float liters_per_mile = avarage_fuel_per_mile(miles_one_year_ago, miles_today, liters); /* report */ printf("average liters per mile: %.2f\n", liters_per_mile); /* quit */ return 0; }