1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <stdio.h>
#include <string.h>
//FUNCTION PROTOTYPES
void getString(const char* prompt, char *buffer, int maxlength);
int getInt(const char* prompt);
int main()
{
//DECLARE VARIABLES
int trash=0;
int lMTot=0;
int monthTot=0;
int retVal = 0;
float rate=350.00;
char hauler [20];
//PRIME READ OF HAULER
getString("Enter your company name", hauler, 19);
while (trash != -1)
{
printf("Enter amount of trash in tons, or enter a -1 to quit.\n");
trash=getInt("Enter the amount of trash in tons");
if (trash !=-1)
monthTot += (trash * rate);
}
printf("Your monthly total is:$ %d\n", monthTot);
lMTot=getInt("Enter the amount from last months total in tons");
while(lMTot <= trash)
{
if(lMTot <= trash)
retVal = (lMTot - monthTot)*(rate);
else
retVal = (monthTot * rate) ;
}
printf("Your total amount due is:$ %f%d\n", &retVal);
printf("Hauler name: %s owes: %d for the month\n", &hauler,&retVal);
return 0;
}
void getString(const char* prompt, char *buffer, int maxlength)
{
printf("%s: ", prompt);
fgets(buffer, maxlength, stdin);
}
int getInt(const char* prompt)
{
int retVal;
printf("%s: ", prompt);
scanf("%d", &retVal);
return retVal;
}
|