well i was just showing where i called it but that was the function that asks the question.
but i can show you everything
Code:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
int get_int(char msg[]);
double get_double(char msg[]);
void display(char hauler[][40], double tot_trash[], int i);
int main()
{
char hauler[40][40];
char msg[200];
char end = ' ';
int trash = 0;
int l_trash;
int i = 0;
double tot_trash[40] = { 0.0 };
double rate;
double total = 0.0;
while(end != 'Y')
{
printf("What is your name");
gets(hauler[i]);
printf("\n");
while(trash != 0)
{
strcpy(msg,
"Enter how much trash you took out(0 to stop)? \n");
trash = get_int(msg);
tot_trash[i] += trash;
}
strcpy(msg, "How Much trash did you dump last month? \n");
l_trash = get_int(msg);
if(trash < l_trash)
total = 350.00 * trash;
else
{
strcpy(msg, "Enter the Tonnage Rate? \n");
rate = get_double(msg);
total = 350.00 * l_trash;
total += (350.00 + rate) * (trash - l_trash);
}
i++;
printf("Do you want to enter a new hauler(y or n)? %s\n", end);
end = getch();
end = toupper(end);
display(hauler, tot_trash, i);
}
return 0;
}
int get_int(char msg[])
{
int dummy;
char buf[40];
printf(msg);
gets(buf);
dummy = atoi(buf);
return dummy;
}
double get_double(char msg[])
{
char buf[40];
printf(msg);
gets(buf);
return atof(buf);
}
void display(char hauler[][40], double tot_trash[], int i)
{
for(int j = 0; j < i; j++)
{
printf("Hauler: %s spent %d\n", hauler[j], tot_trash[j]);
}
}