I just started learning C language, please help me with my problem.
**Using getchar() the program after executed and done with input doesn't close until I press enter. Q1.) In the code below the getchar() doesn't work but why?
But after adding another getchar() [ shown below] cmd doesn't close now.
Q2.) Why, is that typing two getchar() doesn't close the cmd?
**Using getchar() the program after executed and done with input doesn't close until I press enter. Q1.) In the code below the getchar() doesn't work but why?
Code:
#include <stdio.h>
int main(void)
{
int height, length, width, volume, weight;
printf("Enter height of box: ");
scanf("%d", &height);
printf("Enter length of box: ");
scanf("%d", &length);
printf("Enter width of box: ");
scanf("%d", &width);
volume = height * length * width;
weight = (volume + 165) / 166;
printf("Volume (cubic inches): %d\n", volume);
printf("Dimensional weight (pounds): %d\n", weight);
getchar();
return 0;
}
But after adding another getchar() [ shown below] cmd doesn't close now.
Code:
#include <stdio.h>
int main(void)
{
int height, length, width, volume, weight;
printf("Enter height of box: ");
scanf("%d", &height);
printf("Enter length of box: ");
scanf("%d", &length);
printf("Enter width of box: ");
scanf("%d", &width);
volume = height * length * width;
weight = (volume + 165) / 166;
printf("Volume (cubic inches): %d\n", volume);
printf("Dimensional weight (pounds): %d\n", weight);
getchar(); getchar();
return 0;
}