I can't seem to figure out what's wrong; I get a clean compile but after inputting the first number, it crashes.
for (day = 1; day < 15; day++)
{
do
{
printf("What is the temperature high for day #%d? ", day++);
scanf("%d", temperature[day]);
sum += temperature[day];
if (temperature[day]<0 || temperature[day]>100)
{
printf("\nOut of range, please enter a value from 0 to 100\n\n");
}
if (temperature[day] < 60)
{
cold++;
}
else if (temperature[day] >= 60)
{
warm++;
}
else if (temperature[day] > 69 || temperature[day] < 80)
{
printf("Wow! It's in the 70's today!");
warm++;
}
Any help, even a hint, would be greatly appreciated!!
You haven't shown the definition of temerature
, but based on your usage,
scanf("%d", temperature[day]);
should almost certainly be
scanf("%d", &temperature[day]);
When you want to input from the user , you must provide &
sign in scanf() function like below,
scanf("%d", &temperature[day]);
You are missing &
sign in your scanf() function. Add it and your problem will be solved.
mismatch between int and int *.
scanf("%d", &temperature[day]);
instead of
scanf("%d", temperature[day]);
for (day = 1; day < 15; day++) { do
Why do you have both for()
and do()
(presumably do-while()
)?
{ printf("What is the temperature high for day #%d? ", day++);
Do not increment day
here, it is already incremented as part of the for
loop, otherwise the interpretation of day
in rest of the body of the loop is wrong!
scanf("%d", temperature[day]);
It might be scanf("%d", & temperature[day]);
, because scanf()
need the address of the variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.