I have tried to run this program, but its not working as its expected. The program is ending just after I entered quantity amount. Its not displaying the
“printf(“You have selected %s and total quantity is %d. Total amount for this selection is %.2fn”, itemName, quantity, (price * (float)itemQuantity));”
this printf result output.
This is the source code:
#include <stdio.h>
int main() {
float price;
int itemQuantity;
char itemName[51];
printf("Enter the item's name:n");
fgets(itemName,51,stdin);
printf("Enter the quantity amount:n");
scanf("%d", itemQuantity);
printf("Enter the item price:n");
scanf("%f", price);
for(int i = 0; i < 51; i++){
if(itemName[i] == 'n'){
itemName[i] = '';
}
}
printf("You have selected %s and total quantity is %d. Total amount for this selection is %.2fn", itemName, quantity, (price * (float)itemQuantity));
return 0;
}
New contributor
Buddhika Lahiru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.