Reputation: 311
This is a homework assignment, so I am not wanting you to completely write the missing code. But I need a pretty hard push because I am new and need to get familiar with what I am doing.
This is a formatpiece used in AddDetailsblablablafunction()
#define REPLNEFORMT3 " %-7s%7f%4f\n"
Line 51 is a prototype of function
51 void AddDetailToAccumulators(float *totpayrate, *float p);/
Line 85 is In the main mopdule and calls the AddDetailToAccumulators() function
85 AddDetailToAccumulators(float *totpayrate, *float p);
171 void AddDetailToAccumulators(float *totpayrate, float *p)//3.6
172 {
173 totpayrate = p + totpayrate;
174 }
175 void PrintSummaryReport(float totpayrate, FILE * reportfile)/*, float totreg, float *totovt, float totg, float totfed,
176 float totstate, float totssi, float totnet,
177 int numemps, FILE *reportfile)//3.7*/
178
179 {
180 fprintf(stdout,REPLNEFORMT3,totpayrate);
181 fprintf(reportfile,REPLNEFORMT3,totpayrate);
182}
The compiler errors are listed as follows:
g++ -Wall -o "main" "main.cpp" (in directory: /media/dylan07/541C-D0D8)
main.cpp:51:49: error: expected identifier before ‘*’ token
void AddDetailToAccumulators(float *totpayrate, *float p);//, //float *totp, float reg, float *totreg,
^
main.cpp:51:50: error: expected ‘,’ or ‘...’ before ‘float’
void AddDetailToAccumulators(float *totpayrate, *float p);//, //float *totp, float reg, float *totreg,
^
main.cpp: In function ‘int main()’:
main.cpp:85:29: error: expected primary-expression before ‘float’
AddDetailToAccumulators(float *totpayrate, *float p);
^
main.cpp:85:49: error: expected primary-expression before ‘float’
AddDetailToAccumulators(float *totpayrate, *float p);
^
main.cpp: In function ‘void AddDetailToAccumulators(float*, float*)’:
main.cpp:173:19: error: invalid operands of types ‘float*’ and ‘float*’ to binary ‘operator+’
totpayrate = p + totpayrate;
^
main.cpp: In function ‘void PrintSummaryReport(float, FILE*)’:
main.cpp:180:40: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘double’ [-Wformat=]
fprintf(stdout,REPLNEFORMT3,totpayrate);
^
main.cpp:180:40: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat=]
main.cpp:180:40: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat=]
main.cpp:181:44: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘double’ [-Wformat=]
fprintf(reportfile,REPLNEFORMT3,totpayrate);
^
main.cpp:181:44: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat=]
main.cpp:181:44: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat=]
Compilation failed.
I hope my formatting is good. :)
EDIT: BurningLights, I love you!
Upvotes: 1
Views: 161
Reputation: 78
On line 51 the compiler is telling you that the indirection operator(*) is used but you don't have a type declaration before it, so change to float * p.
On line 173 it's telling you that you didn't give enough format arguments for the string REPLNEFORMT3, it expects 3 but you only gave it one.
Upvotes: 0
Reputation: 2397
Okay, so here's why you're getting your errors.
For the first and second errors, your *float
should be float *
. Doing *float
doesn't mean anything to the compiler, and so generates an error. Doing float *
on the other hand, tells the compiler your want a pointer to a float, and is perfectly valid.
For the third and fourth errors, you made the mistake of including the types in your function call. Don't do this! It generates an error. Simply remove the types so it looks like AddDetailToAccumulators(totpayrate, p);
and that will fix your errors, assuming totpayrate and p are pointers to floats defined in your main function.
For the fifth error, you're trying to add two pointers together. That doesn't work! I assume you're trying to use the values that are pointed to, so you need to add the dereference operator (*) to make it look like: *totpayrate = *p + *totpayrate;
.
For the sixth error and the warnings, your format string " %-7s%7f%4f\n"
tells fprintf()
that it should expect a string argument, and then two float/double arguments to be able to write out to the output stream in the specified format. However, you proceed to only give it a single float argument. I can't exactly tell you how to fix this one, since I don't know the intent of the format string, or what you're supposed to be printing. I can tell you that you'll either need to change your format string so it only needs a single float and no string, or add more parameters to your PrintSummaryReport()
function so you can give fprintf()
what your format string tells it that it should expect.
Upvotes: 4