I have a program that asks for the temperature and returns a response depending on what the temperature is.
int main(void)
{
while(1)
{
int temp;
printf("What is the temperature?\nTemp: "); // fetch temperature
scanf("%d", &temp);
if (temp == -858993460) // for some reason parsing "q" returns this value
{
break;
}
in
// Att trycka q först funkar, men om man först skriver in en tempratur så funkar det inte att i senare iterations skriva q, då tar programet bara den senaste inlagda tempraturen
#include <stdio.h>
#include <stdlib.h>
#pragma warning (disable: 4996)
int main(void)
{
while(1)
{
int temp;
printf("What is the temperature?\nTemp: "); // fetch temperature
scanf("%d", &temp);
if (temp == -858993460) // for some reason parsing "q" returns this value
{
break;
}
// check the temperature against diffrent values
if (temp > 32 && temp < 40)
{
printf("%d is too hot!", temp);
}
else if (temp > 18 && temp < 33)
{
printf("%d is a good temperature", temp);
}
else if (temp > 39)
{
printf("It's %d degrees, turn on your AC!", temp);
}
else if (temp < 19)
{
printf("%d is too cold!", temp);
}
else
{
printf("Something has went very wrong...")
}
printf("\n\n----------\n\n");
}
return 0;
}
if you input "q" during the first iteration it works as expected:
temperatur.exe (process 26592) exited with code 0. Press any key to close this window . . .
but inputting a number during the first iteration, the "q" during iteration n>1
returns
(assume first input is "12" second input is "q")
What is the temperature?
Temp: 12
12 is too cold!
----------
What is the temperature?
Temp: q
12 is too cold!
----------
What is the temperature?
Temp: 12 is too cold!
----------
What is the temperature?
Temp: 12 is too cold!
----------
...
I can't find anything on any forums of anyone having a similar issue