With the below program, whenever I enter an amount for bookcost, it reads 0. I've tried a few different things but I cannot seem to get it to use my input.
Around line 49 is where I ask for user input.
Any thoughts would be aweosme.
Code:
//Tschippert
//September 21st-22nd, 2012
#include <stdio.h>
int main ()
{
// Defining Integers//
//
int bookproduct;
int bookcount;
float bookcost;
float bookcost2;
int totalbookcount;
float totalcost;
unsigned int counter;
unsigned int looprun;
// Initializing Integers//
//
counter=0;
totalbookcount=0;
totalcost=0;
bookcount=0;
//Begininng Loop//
//
printf("Would you like to enter a book? 1 for yes, 2 for no.");
scanf(" %d", &looprun);
while (looprun !=2) {
counter++;
printf("\nEnter the Book Product Number:\n");
scanf(" %d", &bookproduct);
printf("\nEnter the Number of Books Purchased: (Negative if you are returning)\n");
scanf(" %d", &bookcount);
printf("\nEnter the Cost of the Book Purchased:\n");
scanf(" %.2f", &bookcost);
while(getchar() != '\n'); //Fix for input stream//
bookcost2= (float) bookcost*bookcount;
printf("\nYou entered %d of product %d for %.2f.\n", bookcount, bookproduct, bookcost2); //Displays what was entered//
printf("\nWould you like to add another book? 1 for yes, 2 for no.\n"); //Asks if user wants to continue//
scanf(" %d", &looprun); //Changes value of looprun to with continue the loop or end the loop//
totalbookcount = totalbookcount+bookcount; //Sums up the entered information for a final display.//
totalcost = (float) (totalcost+bookcost2);
}
if (counter>0) {
printf("\nNumber of records entered: %d", counter);
printf("\nTotal Number of Books: %d", totalbookcount);
printf("\nTotal Cost of Books: %.2f", totalcost);
}
else {
printf("You did not enter any books!");
}
//Totaling inputed values//
//
//Reiterating entered information//
//
//Counter for number of runs
}