A mock for my 2nd in class test using 'if' statements. Not THE most efficient way of doing it, but it functions, and the code is fairly neat. I was happy with this.
Here is the source code:
#include<stdio.h> #include<stdlib.h> int main() { Â Â Â int fuelType, engineSize, cost; Â Â Â printf("Please enter 1 if your car is petrol, and 2 if diesel: "); Â Â Â scanf("%d", &fuelType); Â Â Â printf("\nPlease enter your engine size in cubic cm: "); Â Â Â scanf("%d", &engineSize); Â Â Â if((fuelType==1)) Â Â Â { Â Â Â Â Â Â Â if((engineSize<=1900)) Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â cost=30; Â Â Â Â Â Â Â Â Â Â Â printf("\nYour running costs for 100 miles will be %d pounds.\n", cost); Â Â Â Â Â Â Â } Â Â Â Â Â Â Â else if((engineSize>1900)&&(engineSize<=2100)) Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â cost=40; Â Â Â Â Â Â Â Â Â Â Â printf("\nYour running costs for 100 miles will be %d pounds.\n", cost); Â Â Â Â Â Â Â } Â Â Â Â Â Â Â else if((engineSize>2100)) Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â cost=50; Â Â Â Â Â Â Â Â Â Â Â printf("\nYour running costs for 100 miles will be %d pounds.\n", cost); Â Â Â Â Â Â Â } Â Â Â } Â Â Â else if((fuelType==2)) Â Â Â { Â Â Â Â Â Â Â if((engineSize<=1900)) Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â cost=35; Â Â Â Â Â Â Â Â Â Â Â printf("\nYour running costs for 100 miles will be %d pounds.\n", cost); Â Â Â Â Â Â Â } Â Â Â Â Â Â Â else if((engineSize>1900)&&(engineSize<=2100)) Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â cost=45; Â Â Â Â Â Â Â Â Â Â Â printf("\nYour running costs for 100 miles will be %d pounds.\n", cost); Â Â Â Â Â Â Â } Â Â Â Â Â Â Â else if((engineSize>2100)) Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â cost=55; Â Â Â Â Â Â Â Â Â Â Â printf("\nYour running costs for 100 miles will be %d pounds.\n", cost); Â Â Â Â Â Â Â } Â Â Â } Â Â Â return 0; }






