ysxapp
ysxapp

Reputation: 21

C doesn't show code after entering it in console

I am currently doing college task to create a simple program using C, to enter and display prices of shirts in store. The problem is about that it doesn't show prices after I enter them in console. I don't really understand what is the problem, because my experience in coding on C ~1 week. Can anyone help with that? Thanks.

int main(void)
{
   float small = 0.0; 
   float medium = 0.0; 
   float large = 0.0;
   float total = 0.0;
   printf("Set Shirt Prices\n");
   printf("================\n");
   printf("Enter the price for a SMALL shirt: $");
   scanf("%f", &small);
   printf("Enter the price for a MEDIUM shirt: $");
   scanf("%f", &medium);
   printf("Enter the price for a LARGE shirt: $");
   scanf("%f\n", &large);
   printf("Shirt Store Price List\n");
   printf("======================\n");
   printf("SMALL : $%f\n", small);
   printf("MEDIUM : $%f\n", medium);
   printf("LARGE : $%f\n", large);
   return 0;
}

Upvotes: 2

Views: 45

Answers (1)

selbie
selbie

Reputation: 104514

This line is problematic:

scanf("%f\n", &large);

It's expecting the user to type a float followed by additional text. Change it to:

scanf("%f", &large);

And if want the end-of-line character, you can prepend it to the next statement.

printf("\nShirt Store Price List\n");

Upvotes: 4

Related Questions