help on this enrollment system in cprogramming when I run the programming the output sometimes fall through example when i enter the student number name and address but when i press enter in the address it skips the scanf in the status and goes to the gender it alse does it when I enter the rate it skips the no of units can you guys help me out


int studentNumber, units, yearLevel, cash, statusLocal;
char studentName[50], address[50], status, gender,course[10], birthday;
float rate , mis , cashTendred , accessment, tutionFee, change; 

      printf(" Enter Student Number : ");
      printf(" Enter Student Name : ");
      scanf("%s", studentName);
      printf(" Enter Address : ");
      scanf("%s", &address);
      printf(" Birhtday: MM/DD/YY ");
      printf(" Status: M/S ");
      scanf("%c", &status);
      printf(" Gender: ");
      scanf("%c", &gender);
      printf(" Course : ");
      scanf("%s",  &course);
      printf(" Year Level : ");
      scanf("%d" ,&yearLevel);
      printf(" Status ([1]Local/[2]International):\n");
      case 1:
           printf(" Rate per unit: ");
           printf(" No of units: ");
           printf(" Miscellaneos fee: ");
           accessment = (rate * units) + mis;
           printf("Total Ascessment: %f",accessment);
           printf(" Mode of Payment: ([1]cash/[2]installment)");
           scanf("%d", &cash);
      case 2:
      if(cash == 1)
           tutionFee= accessment * 0.10;
           printf(" TuitionFee %5.2f",tutionFee);
           tutionFee = accessment / 2;
           printf(" Downpayment : ");
           printf(" Balance ");
      printf(" Cash Tendered : ");
      scanf("%5.2f", cashTendred);
      change = cashTendred - tutionFee;
      printf(" Change: %f5.2",change);

I tried compiling your program and got numerous errors

test.c:4:1: warning: return type defaults to ‘int’
test.c: In function ‘main’:
test.c:19:2: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[50]’
test.c:36:2: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[10]’
test.c:52:4: warning: unknown conversion type character ‘.’ in format
test.c:52:4: warning: too many arguments for format
test.c:58:4: warning: unknown conversion type character ‘.’ in format
test.c:58:4: warning: too many arguments for format
test.c:86:2: warning: unknown conversion type character ‘.’ in format
test.c:86:2: warning: too many arguments for format
test.c:86:7: warning: ‘cashTendred’ is used uninitialized in this function

This is one of your errors:

scanf("%s", &address);

It should be

scanf("%s", address);

Which is discouraged. Try using fgets() instead.

If you use scanf(), you have to know what scanf() does and does not do:

1) For char input, scanf() will take *ONE and one ONLY* char. That means that the newline char from hitting the enter key, is still in the keyboard buffer.

Which means that the NEXT scanf() for a char will be taking the newline FIRST, and say "I've got my char, so I'm done here". Leaving you to believe it has magically "skipped" it's whole input.

2) For number input, scanf() will skip over whitespace char's - including newlines, so it's not a problem if there is a newline in the buffer, left over.

The solution is to put one of these, after EVERY scanf(), immediately:


That will pull off the newline char, and stop the "skipping" behavior that you've seen.

Note carefully, Gerard's advice, above. Don't use &address, if address is a char array, and undoubtedly, fgets is a more polished way of getting user input. Scanf() can be used for most assignments, but you have to know how it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.