Computer Science, asked by prihashagamer1, 11 hours ago

#include

int main()

{

int rating;

printf("Enter your rating according to your experience\n");

scanf("$d", &rating);


switch (rating)

{

case '1': printf("Your rating is 1\n");

break;

case '2': printf("Your rating is 2\n");

break;

case '3': printf("Your rating is 3\n");

break;

case '4': printf("Your rating is 4\n");

break;

case '5': printf("Your rating is 5\n");

break;

default: printf("Your rating is invalid\n");

break;

}

return 0;

}




In this c program im trying to make a system for rating up to 5 from 1 but the result is only executes the default one

pls help me with this c program.

Answers

Answered by robinphili24
1

Answer:

I am not very good at c but I think I the below change should do it.

Explanation:

Seems like you have used ' ' for case 1,2,3,4,5 removing the ' ' should do the trick.

#include

int main()

{

int rating;

printf("Enter your rating according to your experience\n");

scanf("$d", &rating);

switch (rating)

{

case 1: printf("Your rating is 1\n");

break;

case 2: printf("Your rating is 2\n");

break;

case 3: printf("Your rating is 3\n");

break;

case 4: printf("Your rating is 4\n");

break;

case 5: printf("Your rating is 5\n");

break;

default: printf("Your rating is invalid\n");

break;

}

return 0;

}

I tested it and now works fine.

Similar questions