0
I developed a program where the user will inform the year of the vehicle and then the program will display on the screen the discount for the year. I still need to add a way to ask if he wants to calculate again, if not, finish. I can do it in Python if necessary.
The code I wrote:
int
main ()
{
int anocarro;
printf ("Digite o ano de fabricacao do veiculo: \n");
scanf ("%i", &anocarro);
if (anocarro <= 2010);
printf ("%i", "\nO desconto sera 7%");
else (anocarro >= 2010);
printf ("%i", "\nO desconto sera 12%");
}
The mistakes were:
main.c:19:13: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 > has type ‘char *’ [-Wformat=] printf ("%i", "\nO desconto sera 7%"); ^ main.c:20:3: error: ‘else’ without a previous ‘if’ else (anocarro >= 2010); ^~~~ main.c:21:13: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=] printf ("%i", "\nO desconto sera 12%");
Doesn’t have this
;
at the end of the if line (this ; is closing the if command). It makes no sense to specify a %i format if you are not printing a number. Use:printf ("\nO desconto sera 7%");
. You could even useprintf ("%s", "\nO desconto sera 7%");
but I don’t see much point.– anonimo