我正在尝试为班级建造天气计算器。
问题似乎与我的if-else语句有关。 if if应该根据平均温度打印出关于天气状况的单独陈述。由于某种原因,该程序总是输出第二个声明:" \ n这两个星期非常热"。
如何正确构建if-else语句?
#include <stdio.h>
int main(void){
int high_temp[14];
int warmdays = 0, colddays = 0, i = 0;
float average = 0.0f, sum = 0.0f;
printf("\nWeather Analyzer Application by Joey Peters");
for(i = 0; i < 14; i++) {
printf("\n\nPlease enter the temperature for day #%d ", i+1);
scanf("%d", &high_temp[i]);
sum += high_temp[i];
if(high_temp[i] > 60){
warmdays++;
}
if(high_temp[i] < 60){
colddays++;
}
}
average = sum / 14;
printf("\nThe number of warm days: %d", warmdays);
printf("\nThe nuber of cold days: %d", colddays);
printf("\nThe average high temperature: %.2f", average);
if(average = 100 || average >= 90 ){
printf("These two weeks were blazing hot");
}
else
if(average >= 80 || average <= 89){
printf("\nThese two weeks were quite hot");
}
else
if(average >= 70 || average <= 79){
printf("\nThese two weeks hot for Michigan");
}
else
if(average >= 60 || average <= 69){
printf("\nThese two weeks were decent for Michigan");
}
else
if(average >= 50 || average <= 59){
printf("\nThese two weeks were somewhat cold");
}
else
if(average < 50){
printf("\nThese two weeks were basically cold");
}
printf("\n\nThank you for using the weather analyzer!");
return 0;
}
答案 0 :(得分:1)
你所在的行
if(average = 100 || average >= 90 )
您要为x分配100,而不是比较它。将其更改为:
if(average == 100 || average >= 90 )
或者通过将其更改为
进一步简化 if(average >= 90 )
如果你已经检查average
是否大于90,那么检查average
是否为100就没有意义。
此外,如果您要检查&&
是否介于两个数字之间(例如80和89),请使用if(average >= 80 && average <= 89)
运算符:
Query optimization
Tips and best practices
• Query multiple tables
• 3 Days using comma separated table names
• Last 7 Days using TABLE_DATE_RANGE
• Last 3 Months using TABLE_DATE_RANGE
• Last 1 Year using TABLE_DATE_RANGE
• Specific Date Range
• Last 6 Days plus Today’s data (intraday) using multiple TABLE_DATE_RANGE
Basic query examples
• Total [metric] per [dimension]
• Average bounce rate per [dimension]
• Average number of product pageviews by purchaser type
• Average number of transactions per purchaser
• Average amount of money spent per session
• Sequence of hits (pathing analysis)
• Multiple custom dimensions at hit or session level
Advanced query examples
• Products purchased by customers who purchased Product A (Classic Ecommerce)
• Products purchased by customers who purchased product A (Enhanced Ecommerce)
• Average number of user interactions before purchase
• Percentage of stock sold per product
• Profitability of each product
• Real profitability of each product