3
When trying to create a program that converts Celsius into Fahrenheit to get practical and I come across the following error message:
Erro "sair " undeclared (first use in this function)
My intention as the do while
was to create an output option for the user. The rest of the code at first works as expected.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
do
{
int sair;
float temp,formula;
puts("Graus Celsius:");
scanf("%f",&temp);
system("cls");
formula = temp * 1.8 + 32;
printf("\nCelsius:%.1f\n\nFahrenheit:%.1f\n\n",temp,formula);
puts("Digite 1 para sair ou 2 para uma nova conversao...\n");
scanf("%d", &sair);
}
while(sair == 1);
{
return(0);
}
}
Why you don’t like variables used as a flag?
– Ronaldo Araújo Alves
I avoid state, avoid state mutation, avoided larger scope that should be in state. Flag is always an avoidable state, so I avoid. State and its mutation is the cause of most bugs. In functional languages there is no way to have flags. Flag seems to be gambiarra because he can’t find the right condition. This is a case that is not the most serious, but it is still ugly to have to declare the variable out when you do not need it out of the block (for me it is until error of the language not accept so). Some think there shouldn’t even be
do-while
and always be like I did, when it has at least 1 exec.– Maniero