0

So I'm trying to let the user enter their grades (A to F), capital or small letters, until they input a !. then print out how many grades they inputted.

`

#include <stdio.h>
int main()
{

    char ocjena;
    int zbrojUkupan = 0, zbrojA = 0, zbrojB = 0, zbrojC = 0, zbrojD = 0, zbrojF = 0;



    do {
    printf("Unesite svoje ocjene:\n");
    scanf("%c", &ocjena);

    switch(ocjena){
    case 'A':
    case 'a':
        zbrojA += 1;
        zbrojUkupan += 1;
        break;
    case 'B':
    case 'b':
        zbrojB += 1;
        zbrojUkupan += 1;
        break;
    case 'C':
    case 'c':
        zbrojC += 1;
        zbrojUkupan += 1;
        break;
    case 'D':
    case 'd':
        zbrojC += 1;
        zbrojUkupan += 1;
        break;
    case 'F':
    case 'f':
        zbrojC += 1;
        zbrojUkupan += 1;
        break;
    default:
        printf("Unijeli ste krivu ocjenu\n");
    }
    } while (ocjena != '!');
    printf("Broj unesenih ocjena je %d, zbroj A je %d, zbroj B je %d, zbroj c je %d, zbroj F je %d", zbrojUkupan, zbrojA, zbrojB, zbrojC, zbrojD, zbrojF);


    return 0;
}

`

Why is this code not working? It keeps printing out stuff two times. How do I make this work?

lala
  • 1
  • 2
  • https://stackoverflow.com/questions/5240789/scanf-leaves-the-newline-character-in-the-buffer – pm100 Nov 06 '22 at 18:51
  • 2
    Does this answer your question? [scanf() leaves the newline character in the buffer](https://stackoverflow.com/questions/5240789/scanf-leaves-the-newline-character-in-the-buffer) – pm100 Nov 06 '22 at 18:54

1 Answers1

0

I don't understand what you are trying to do but your default case is missing a break;

HmBloqued
  • 62
  • 3