URI Online Judge Solution 1134 Type of Fuel using C Programming.
A gas station wants to determine which of their products is the preference of their customers. Write a program to read the type of fuel supplied (coded as follows: 1. Alcohol 2. Gasoline 3. Diesel 4. End). If you enter an invalid code (outside the range of 1 to 4) a new code must be requested. The program will end when the inserted code is the number 4.
Input
The input contains only integer and positive values.
Output
It should be written the message: "MUITO OBRIGADO" and the amount of customers who fueled each fuel type, as an example.
Input Sample | Output Sample |
8
1 7 2 2 4 |
MUITO OBRIGADO
Alcool: 1 Gasolina: 2 Diesel: 0 |
Solution using C :
#include <stdio.h>
int main() {
int n,a,g,d;
a = g = d = 0;
while(1)
{
scanf("%d",&n);
if(n==4)
break;
else if(n==1)
a++;
else if(n==2)
g++;
else if(n==3)
d++;
}
printf("MUITO OBRIGADO\nAlcool: %d\nGasolina: %d\nDiesel: %d\n",a,g,d);
return 0;
}
Comments
Post a Comment