Hello,
I just started with programming C. My first task is to code a simple system that ask a question that you can answer with y (yes) or n (no) and goes to the next question. And at the end gives a statement of what can be the problem.
This is my code:
When i compile it it gives no errors. When i start it it asks the first question and if i answer that with n it gives the second but then it goes to the end of the program in stead of giving the user the change to give new input and scan this. Can anyone tell me what there is wrong?Code:
#include <stdio.h>
void main(void)
{
char answer_1;
char answer_2;
char answer_3;
char answer_4;
char answer_5;
char answer_6;
printf("Maakt de PC enig geluid?\n");
scanf("%c",&answer_1);
if(answer_1=='n')
{
printf("Zit de stekker erin?\n");
scanf("%c",&answer_2);
if(answer_2=='n')
{
printf("Pffffff......\n");
}
if(answer_2=='y')
{
printf("Controleer de voeding (zekering kapot?)\n");
}
}
else
{
printf("Is er geen beeld op het scherm te zien?\n");
scanf("%c",&answer_3);
if(answer_3=='n')
{
printf("Geen 'memory errors' tijdens booten?\n");
scanf("%c",&answer_4);
if(answer_4=='n')
{
printf("Controleer/vervang SIM geheugenkaarten\n");
}
else
{
printf("Zijn er meldingen over hard disk errors tijdens het booten?\n");
scanf("%c",&answer_5);
if(answer_5=='n')
{
printf("Run hardwarediagnoseprogramma. Is alles OK?\n");
scanf("%c",&answer_6);
if(answer_6=='n')
{
printf("Vervang het foutieve onderdeel.\n");
}
else
{
printf("Softwareprobleem: herinstalleer windows\n");
}
}
else
{
printf("Controleer hard drives en kabels./n");
}
}
}
else
{
printf("Controleer videokaart, monitor en bedrading.\n");
}
}
}
Thanks for your help!