In: Computer Science
In C,
1) Create variables for:
your first and last name
total round trip to school and home (assuming you don't live on campus - make it your hometown).
cost of gas
2) Create a program that will:
output your first name and your total miles driven for the week.
output your last name with the total costs per week
Hi buddy, Please find the below C Program. I've added comments for your better understanding
#include <stdio.h>
int main(void) {
// These two variables store the first name and last
name respectively
char first_name[20] = "Micheal";
char last_name[20] = "Johnson";
//Let's make the distance from home to school 2
int distance = 2;
//Let 'cost' be the cost of gas per mile
double cost = 4;
//Total miles per week is TOTAL_WEEK_DAYS (2) *
DISTANCE * 2 (Both for Home to school and School to Home)
int totalMiles = 5 * distance * 2;
printf("%s %d\n",first_name,totalMiles);
//Total cost will be total Miles * Cost per each
mile
double totalCost = totalMiles * cost;
printf("%s %lf\n",last_name,totalCost);
return 0;
}
OUTPUT:
Micheal 20
Johnson 80.000000