My class assignment asks me to prompt the user to input four variable, char float int char, in one input line.
Here is the entire code:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int main(void){
char h = 'a';
char b, c, d, e;
int m, n, o;
float y, z, x;
short shrt = SHRT_MAX;
double inf = HUGE_VAL;
printf("Program: Data Exercises\n");
printf("%c\n", h);
printf("%d\n", h);
printf("%d\n", shrt);
printf("%f\n", inf);
printf("Enter char int char float: ");
scanf("%c %d %c %f", &b, &m, &c, &y);
printf("You entered: '%c' %d '%c' %.3f \n", b, m, c, y);
This section of code is where I am having the issue.
printf("Enter char float int char: ");
scanf("%c %f %d %c", &d, &z, &n, &e);
printf("You entered: '%c' %f %d '%c' \n", d, z, n, e);
This part works if I isolate the above section.
printf("Enter an integer value: ");
scanf("%d", &o);
printf("You entered: %15.15d \n", o);
printf("Enter a float value: ");
scanf("%f", &x);
printf("You entered: %15.2f \n", x);
return 0;
}
Seeing as I cannot post images due to not having a high enough rep, I will provide a link to a screen-cap of the console when running the program.
I would really appreciate if someone could explain to me why the program is not working correctly. Thanks in advance.