Just a to let you know, I began learning C few days ago so I only know some syntax. Anyways, here is the problem. I dont know if, if(char var == 'character') is wrong or is there different way to multiply different floats? Thank you in advance
Code:
#include <stdio.h>
#include <stdlib.h>
#define offroad 2.2
#define motorway 1.3
int main()
{
float way1;
float mile1;
float way2;
float mile2;
float way3;
float mile3;
char answer1 [2];
char answer2 [2];
char answer3 [2];
//Ask options to calculate results
printf("Please enter the information in order to obtain your results\n");
printf("Will the road be a motorway(m) or offroad (o)?\n");
scanf(" %c", answer1);
printf("What distance in KM will you cover?\n");
scanf(" %f", &way1);
printf("Will the road be a motorway(m) or offroad (o)?\n");
scanf(" %c", answer2);
printf("What distance in KM will you cover?\n");
scanf(" %f", &way2);
printf("Will the road be a motorway(m) or offroad (o)?\n");
scanf(" %c", answer3);
printf("What distance in KM will you cover?\n");
scanf(" %f", &way3);
mile1 = way1;
mile2 = way2;
mile3 = way3;
// Here is my problem way1 = way1 * motorway etc. doesnt work or the "if(answer1 == 'm')" statement is wrong.
if(answer1 == 'm'){
way1 *= motorway;
}
if(answer1 == 'o'){
way1 *= offroad;
}
if(answer2 == 'm'){
way2 *= motorway;
}
if(answer2 == 'o'){
way2 *= offroad;
}
if(answer3 == 'm'){
way3 *= motorway;
}
if(answer3 == 'o'){
way3 *= offroad;
}
//Convert way variables into miles
mile1 *= 1.6;
mile2 *= 1.6;
mile3 *= 1.6;
printf("Trip 1 will be %.3f miles and use %.3f liters of fuel\n", mile1, way1);
printf("Trip 2 will be %.3f miles and use %.3f liters of fuel\n", mile2, way2);
printf("Trip 3 will be %.3f miles and use %.3f liters of fuel\n", mile3, way3);
return 0;
}