I am familiar with storing and printing characters using getchar(); and putchar();. However, when I use it with my entire code, it does not seem to work. In the command window, it will take the character, but not print it. Thus, I have no idea what the computer is doing. I tried the code for storing and printing a character on its own and it works fine.
int ans;
printf("\n\t Would you like to remove an item from your cart? (Y or N): ");
ans = getchar();
printf("\n\t ");
putchar(ans);
But as soon as I use it with the entire code, it does not work properly.
#include <stdio.h>
void main()
{
float items[6];
float sum;
float taxSum;
printf("\n\n\n\n");
printf("\t Please enter the price for Item 1: ");
scanf_s(" %f", &items[0]);
while (!((items[0] >= 0.001) && (items[0] <= 999.99)))
{
printf("\n\t [ERROR] Please enter number between $0.01 and $999.99: ");
scanf_s(" %f", &items[0]);
}
int ans;
printf("\n\t Would you like to remove an item from your cart? (Y or N): ");
ans = getchar();
printf("\n\t ");
putchar(ans);
I'm extremely curious as to why that is and what I need to do to get it work.