Home > database >  I cannot enter the value for type2 or grind2 or wght2 in the output what is the error?
I cannot enter the value for type2 or grind2 or wght2 in the output what is the error?

Time:01-23

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

    
    char type1, grind1, cream1;
    int wght1;
    double temp1;

    char type2, grind2, cream2;
    int wght2;
    double temp2;


    printf("COFFEE-1...\n");
    printf("Type ([L]ight,[B]lend): ");
    scanf("%c", &type1);
    printf("Grind size ([C]ourse,[F]ine): ");
    scanf(" %c", &grind1);
    printf("Bag weight (g): ");
    scanf(" %d", &wght1);
    printf("Best served with cream ([Y]es, [N]o): ");
    scanf(" %c", &cream1);
    printf("Ideal serving temperature (Celcius): ");
    scanf(" %.1lf", &temp1);
    printf("\n");

    printf("COFFEE-2...\n");
    printf("Type ([l]ight,[B]lend): ");
    scanf(" %c", &type2);
    printf("Grind size ([C]ourse,[F]ine): ");
    scanf(" %c", &grind2);
    printf("Bag weight (g): ");
    scanf(" %d", &wght2);
    printf("Best served with cream ([Y]es,[N]o): ");
    scanf(" %c", &cream2);
    printf("Ideal serving temperature (Celcius): ");
    scanf(" %.1lf", &temp2);
    printf("\n");


    return(0);
}

i can enter the value for type1,grind1,wght1,cream1 and temp1 but not for the 2nd time ........ I'm new to coding and my assignment is due tomorrow welp T_T

CodePudding user response:

The format specifier %.1lf is not correct.

Unlike printf format specifiers, scanf format specifiers don't take a precision, so remove it.

scanf(" %lf", &temp1);
...
scanf(" %lf", &temp2);

CodePudding user response:

for me i would code "printf" and "scanf" twice in order to input values twice.

  •  Tags:  
  • Related