Hi,
I've written a program where everything works fine except one thing. The program is a series of questions and 'if statements' based on the answers.
The only thing not working is snow = getchar(), water = getchar(), and muchsnow = getchar(), never get executed. The questions above them get printed, followed by the next question on the list which meets the requirements for the if statements. For the life of me I cannot figure out why this is happening. Any help would be appreciated.
Code:include "main.h" int main() { int season, sky; char water = 'b', snow = 'y', muchsnow = 'b', temp = 'b'; printf("What season is it?: \n1. Winter\n2. Spring\n3. Summer\n4. Autumn\nPlease Enter the number corresponding with your selection."); scanf("%i", &season); printf("Is it sunny or cloudy?: \n1. Sunny\n2.Cloudy\nPlease enter your selection: "); scanf("%i", &sky); if(sky == 2) { if(season == 1) { printf("Is it snowing?: y/n "); snow = getchar(); } if(season != 1) { printf("Is it raining?: y/n "); water = getchar(); } } if(season == 1) { printf("Is there alot of snow on the ground?: y/n "); muchsnow = getchar(); } printf("Is the tempreture normal for the season: y/n"); temp = getchar(); if(((season == 1)&&(sky==1)&&(muchsnow = 'y'))||((season == 3)&&(sky ==1))) { printf("You should wear sunglasses"); } if(((season == 2)||(season == 4))&&(sky == 2)) { printf("You might want to bring a jacket"); } if(water=='y') { printf("You should bring an umbrella"); } if(((season == 2)||(season == 4))&&(sky ==1)) { printf("You should bring a hat"); } return 0; }



LinkBack URL
About LinkBacks



It works great now. 

