having trouble w/ strings & function headers

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
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <string.h>

//FUNCTION PROTOTYPES
int getMonthTot();
int getLastMonthTot();
float getCalcRate();
char getString();
void displayFinalReport();


int main()
{
	//DECLARE VARIABLES
	int trash=0;
	int lMTot=0;
	int monthTot=0;
	float rate=350.00;
	char hauler [20]; 

	//PRIME READ OF HAULER
	printf("Enter amount of trash in tons, or enter a -1 to quit.\n");
	hauler=getString();
	trash=getMonthTot();
	lMTot=getLastMonthTot();
	rate=getCalcRate();
	
	return 0;
}

	char getString(hauler)
	{
		printf("Enter your company name: ");
		return hauler;
	}
	int getMonthTot();
	{
		printf("Enter the amount of trash in tons: \n");
		return trash;
	}
	int getLastMonthTot();
	{
		printf("Enter the amount from last months total in tons: \n");
		return lMTot;
	}
	float getCalcRate();
	{
		printf("%d\n",rate);
		while(hauler != -1)
		{
			if(trash<lMTot)
			{
				trash = rate * monTot;
			}
			else
				trash = monthTot + (lMTot - monthTot) * rate;
		}//END OF WHILE
		return rate;
	}//END OF CALC RATE
	void displayFinalReport();
	{
		printf("To see final report,\n");
		system("pause");
		system("CLS");

		printf("Total Haulers : %d ",haulers);
		printf("Total Charge : %f", rate);
	}
This function:
1
2
3
4
5
	int getMonthTot();
	{
		printf("Enter the amount of trash in tons: \n");
		return trash;
	}
Prints "Enter the amount of trash in tons: \n" and tries to return an unexisting variable
Many other functions do the same
hauler=getString();


but

char getString(hauler)

your not passing any parameters to the function which expects a something.... It's written wrong. it should be either:

char getString()

or

char getString(char hauler)

EDIT: Baz beat me to it: none of your functions are getting input, they are simply printing out a string then returning a variable which is void
Also unless you need to use character arrays you should just use std::string, much easier.(and your including string.h but not using it)

Last edited on
I am still having a problem that shows an error for C2447 missing function header; is there a particular header that needs to be used in this program?
Most of those function definitions are wrong.
They look like this (Notice the incorrect semi-colon - obviously a copy and paste error):
	int getMonthTot(); //ERROR semicolon
	{
		printf("Enter the amount of trash in tons: \n");
		return trash;
	}


That is what error C2447 is warning you about.

This is the only one that is written correctly.
	char getString(hauler)
	{
		printf("Enter your company name: ");
		return hauler;
	}
Last edited on

This is the only one that is written correctly.

1
2
3
4
5
	char getString(hauler)
	{
		printf("Enter your company name: ");
		return hauler;
	}




That's not correct either. It needs a name for the object hauler, or needs a type for the name hauler.eg, (char hauler) (hauler h)

As far as missing function header, you should re-paste your updated code so we can have a look at it. I'm going to take a wild stab in the dark and say you probably need to #include <iostream>
Last edited on
This is how I have it written now, all seems to be working except for the results. I need to print out 'if the amount of trash collected this month is less than last month, the charge is 350. per ton; but if amount is greater than the previous month prompt the user for that total. apply the excess for current month & add amount to calculated amount.

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;
}
Topic archived. No new replies allowed.