What's wrong with this code? When I run it, it first prints the first question, I enter a character (the answer - a or b or c or d), then prints the second question and immediately prints the third question. I can't enter the answer for the second question as well as for the fourth. The code literally jumps over those statements and I don't get why. I get no errors but this works wrong.
Code:
#include <stdio.h>
#include <conio.h>
int points(char,char,char,char,char);
char c1='c', c2='b', c3='b', c4='d', c5='a';
int main() {
char a1, a2, a3, a4, a5; int count;
printf("Q1 :Which of the following is a greenhouse gas that is ");
printf("released by human activities and speeds up global warming?\n");
printf("a: petroleum\nb: natural gas\nc: carbon dioxide\nd: nuclear power\n\n"); // carbon dioxide
printf("Your answer: \n\n"); scanf_s("%c",&a1);
printf("Q2: Which of the following human activities does NOT release carbon dioxide into the atmosphere?\n");
printf("a: burning fossil fuels\nb: fishing\nc: deforestation\nd: driving\n\n"); // fishing
printf("Your answer: \n\n"); scanf_s("%c",&a2);
printf("As global warming continues, the intensity of what type of ");
printf("storm that hits coastlines is predicted to increase?");
printf("a: tornadoes\nb: hurricanes\nc: tsunamis\nd: earthquakes\n\n"); // hurricanes
printf("Your answer: \n\n"); scanf_s("%c",&a3);
printf("Q4: Rising water temperatures is a result of global warming and may eventually ");
printf("increase sea levels due to the dissolving of what?\n");
printf("a: mountains\nb: wetlands\nc: river beds\nd: glaciers\n\n"); // glaciers
printf("Your answer: \n\n"); scanf_s("%c",&a4);
printf("What country emits the most carbon dioxide?\n");
printf("a: China\nb: United States\nc: Russia\nd: India\n\n"); // China
printf("Your answer: \n\n"); scanf_s("%c",&a5);
count=points(a1,a2,a3,a4,a5);
printf("YOUR SCORE: %d out of 5\n", count);
switch(count) {
case 5: printf("Excellent\n");
case 4: printf("Very good\n");
case 3: printf("Time to brush up on your knowledge of global warming.\n");
}
_getch();
return 0;
}
int points(char a1,char a2,char a3,char a4,char a5) {
int count=0;
if (a1==c1) {count++;}
if (a2==c2) {count++;}
if (a3==c3) {count++;}
if (a4==c4) {count++;}
if (a5==c5) {count++;}
return count;
}