So my main issue is on the last half of this code in particular this:
printf("Do you want to evaluate another teacher? (y/n) : ");
printf("\n");
scanf(" %c", &loop);
if(loop != 'y' && loop != 3)
loop='n';
I'm creating a program that takes a survey. However, the student can only preform up to 3 surveys and they are asked at the end of every survey if they'd like to preform another. My problem occurs after they have preformed a third survey. After that the survey prompts the same question of Do you want to evaluate another teacher? (y/n) and if the student answers ythe code loops back and lets them take another survey instead of listening to my conditions that state after three surveys the program should automatically end. If they answer n it still re-enters the loop too!
I'm extremely confused as to how to get this portion of my code to coexist with the rest of my code in unison and work. Help would be greatly appreciated!
Here's the entirety of my code if you'd like:
#include <stdio.h>
int main()
{
int i = 0;
char loop='y';
while(loop == 'y' ){
for(i = 0; i<4; i++){
int num1,num2,num3,num4,num5,num6,num7,num8;
int result;
int input;
char name[30];
char teacher[30];
printf("Enter your name : ");
scanf("%s", &name);
printf("\n");
printf("Which teacher do you want to evaluate : ");
scanf( "%s/n", &teacher);
printf("\n");
printf("Answer with 1 for Never upto 7 for Frequently\n");
printf("\n");
printf("How often does the teacher indicate where the class is going? \n ");
scanf("%d",&num1);
printf("How often does the teacher explain material clearly? \n ");
scanf("%d",&num2);
printf("How often is the teacher available outside of class? \n ");
scanf("%d",&num3);
printf("How often does the teacher provide helpful comments on papers and exams? \n ");
scanf("%d",&num4);
printf("How often does the teacher stimulate interest in material? \n ");
scanf("%d",&num5);
printf("How often does the teacher adjust the pace of class to the students' level of understanding? \n ");
scanf("%d",&num6);
printf("How often does the teacher effectively encourage students to ask questions and give answers? \n ");
scanf("%d",&num7);
printf("How is the teacher tolerant of different opinions expressed in class? \n ");
scanf("%d",&num8);
printf("******************************************************************************\n");
printf("******************************************************************************\n");
printf("Student's name : %s.\n", name);
printf("Teacher's name : %s.\n", teacher);
printf("How often does the teacher indicate where the class is going: %d\n",num1);
printf("How often does the teacher explain material clearly : %d\n",num2);
printf("How often is the teacher available outside of class : %d\n",num3);
printf("How often does the teacher provide helpful comments on papers and exams: %d\n",num4);
printf("How often does the teacher stimulate interest in material: %d\n",num5);
printf("How often does the teacher adjust the pace of class to the students' level of understanding: %d\n",num6);
printf("How often does the teacher effectively encourage students to ask questions and give answers: %d\n",num7);
printf("How is the teacher tolerant of different opinions expressed in class: %d\n",num8);
printf("******************************************************************************\n");
printf("******************************************************************************\n");
printf("Do you want to evaluate another teacher? (y/n) : ");
printf("\n");
scanf(" %c", &loop);
if(loop != 'y' && loop != 3)
loop='n';
}
return 0;
}
}
if(loop != 'y' && loop != 3)that's not logical. Isloopthe counter or the variable to store user answer in? choose.if(loop != 'y' && loop != 3) loop='n';be outside the for loop?scanf( "%s/n", &teacher);is interestingly a problem, yet not a problem. (Drop the/n). Usescanf( "%29s", teacher);