I am only a very beginner and was wondering if anyone can give me some help in determining how to fix the error messages i keep getting when i try to compile. I have been pulling my hair out for 3 days. Any help is much appreciated! attached is the code i have come up with so far and the errors down at the bottom as well as what its suppose to do.

#include <stdio.h>
void getInput();
void calculate(int num1, int num2, int num3, float num4);
void printTable(int num1, int num2, int num3, float num4,int calc1, int calc2, int calc3, int calc4, double calc5, double calc6, float calc7, float calc8);

int main (void)


{
int num1, num2, num3, float num4, int calc1, int calc2, int calc3, int calc4, double calc5, double calc6, float calc7, float calc8);

getInput;

calculate;

printTable;
return 0;
}

void getInput ()
{
int num1, num2, num3; 
float num4;
printf("Enter three integers and a floating point number then press enter: ");
scanf("%d %d %d %d" , &num1, &num2, &num3, &num4); 
return ;
}

void calculate (int num1, int num2, int num3, float num4)
{
int calc1, calc2, calc3, calc4; 
double calc5;
double calc6;
float calc7, calc8;

calc1 = num1+num3;
calc2 = num1*num2;
if (num4 < 0) 
{
    calc3 = ((num4/100) %10) * -1;
}
else
{
    calc3 = (num4/100) %10;
}
calc4 = num2/num3;
calc5 = num3 * num4;
calc6 = num3/num1;
calc7 = num1 + num2 + num3 + num4;
calc8 = calc7 / 4;
}

void printTable (int num1, int num2, int num3, float num4, int calc1, int calc2, int cal3, int calc4, double calc5, double calc6, float calc7, float calc8);

{

printf("\n Input 1 (int) :-28%14.2d\n", num1 );
printf("\n Input 2 (int) :-28%14.2d\n", num2 );
printf("\n Input 3 (int) :-28%14.2d\n", num3 );
printf("\n Input 4 (float) :-28%14.2f\n", num4 );
printf("\n Input 1 + Input 3 (int) :-28%14.2d\n", calc1 );
printf("\n Input 1 * Input 2 (int) :-28%14.2d\n", calc2 );
printf("\n Hundreds Digit of Input 4 :-28%14.2d\n", calc3 );
if (num3 !=0)
    printf("%-28s%14d\n","input 2 / Input 3 (int)", calc4);
else
    printf("%-28s%14s\n","input 2 / input 3 (int)", "DIV/0");
printf("\n Input 2 / Input 3 (int) :-28%14.2f\n", calc4 );
printf("\n Input 3 * Input 4 (double) :-28%14.2f\n", calc5 );
if (num3 !=0)
    printf("%-28s%14d\n","input 3 / Input 1 (int)", calc6);
else
    printf("%-28s%14s\n","input 3 / input 1 (int)", "DIV/0");
printf("\n Input 3 / Input 1 (double) :-28%14.2f\n", calc6 );
printf("\n Sum of the input (float) :-28%14.2f\n", calc7 );
printf("\n Average of the input (float) :-28%14.2f\n", calc8 );

return; 
}

ERROR MESSAGES

In function `main':
10 syntax error before "float"
40 invalid operands to binary %
44 invalid operands to binary %
At top level:
55 syntax error before '{' token
55 syntax error before '{' token
58 conflicting types for 'printf'
58 a parameter list with an ellipsis can't match an empty parameter name list declaration
58 conflicting types for 'printf'
58 THROUGH 76 a parameter list with an ellipsis can't match an empty parameter name list declaration.

WHAT IT'S SUPPOSE TO DO
*not allowed to use global variables except for debug flag.
*Prompts the user for three integers and one floating point number.
*Reads the three integers and one floating point number from the user (you can assume that the users enters valid numbers, so you don't need to do error checking.)
*Performs the following calculations
*Calculates the integer sum of the first and third numbers
*Multiplies the first number by the second number for an integer result
*Extracts the 100s digit of the fourth number
*If the third number is not equal to zero, divides the second number by the third number to get the integer result.
*Multiplies the third number by the fourth number to get a double result
*If the first number is not zero, divides the third number by the first number to get a double result
*Floating point sum of the input numbers
*Floating point average of the input numbers
*Prints a table of the input and the results
*The first column should be the description of the value or calculation, left aligned in a column 28 wide.
*The second column should display the value or result, right aligned in a field 14 wide.
*All float or double numbers should be displayed to three digits of precision.
*If the result would be invalid because of a divide by zero, the program should not do the divide, instead it should print the result DIV/0 instead.

Example of what is it suppose to look like

Enter three integers and a floating point number then press enter: 123 -456 524 -987.6

Description                           Data
------------------------------------------
Input 1 (int)                          123
Input 2 (int)                         -456
Input 3 (int)                          524
Input 4 (float)                   -987.600
Input 1 + Input 3 (int)                647
Input 1 * Input 2 (int)             -56088
Hundreds Digit of Input 4                9
Input 2 / Input 3 (int)                  0
Input 3 * Input 4 (double)     -517502.387
Input 3 / Input 1 (double)           4.260
Sum of the input (float)          -796.600
Average of the input (float)      -199.150

its not showing the correct spacing for the tables not too worried bc i know how to space properly... i think

Recommended Answers

All 4 Replies

At the beginning of your "main (void)" function, I see

"{
int num1, num2, num3, float num4, int calc1, int calc2, int calc3, int calc4, double calc5, double calc6, float calc7, float calc8);"

Notice that it ends with a ")", but there is no "(" before it. That must be one of the errors.

Also, I think you may want to use a format more like so:

int num1, num2, num3; 
float num4;
int calc1, calc2, calc3, calc4;
double calc5, calc6;
float calc7, calc8;

I think you must use semicolons before declaring a new "int" or "double", etc.

int main (void)
{
int num1, num2, num3, float num4, int calc1, int calc2, int calc3, int calc4, double calc5, double calc6, float calc7, float calc8);

getInput;

calculate;

printTable;
return 0;
}

should be something more like:

int main ()
{
   int num1, num2, num3;
   float num4, calc7, calc8
   int calc1, calc2, calc3, calc4;
   double calc5 calc6;

   getInput();

   calculate( /* Insert arguments here */);

   printTable( /* Inser arguments here */ );
   return 0;
}

There are other errors in the other functions too, but see how you get on from here :o)

This is the code I have worked on since i first posted. The errors are gone but the program wont run! any ideas?

/* Output: Outout ia the data table thats prints out along with the hello world!
 */

#include <stdio.h>
void greeting(void);
int getInput();
int calculate(int num1, int num2, int num3, float num4);
void printTable(int num1, int num2, int num3, float num4,int calc1, int calc2, int calc3, int calc4, double calc5, double calc6, float calc7, float calc8);

int main (void)


{
int num1, num2, num3; 
float num4;
int calc1, calc2, calc3, calc4;
double calc5, calc6;
float calc7, calc8;

void greeting();

int getInput();

int calculate (int num1, int num2, int num3, float num4);

void printTable (int num1, int num2, int num3, float num4, int calc1, int calc2, 
int calc3, int calc4, double calc5, double calc6, float calc7, float calc8);
return ;
}

void greeting ()
{
return printf("\nHello World! My name is Daniel Greene\n") ;
}




int getInput ()
{
int num1, num2, num3; 
float num4;
printf("Enter three integers and a floating point number then press enter: ");
scanf("%d %d %d %d" , &num1, &num2, &num3, &num4); 
return ;
}

int calculate (int num1, int num2, int num3, float num4)
{
int calc1, calc2, calc3, calc4; 
double calc5;
double calc6;
float calc7, calc8;

calc1 = num1+num3;
calc2 = num1*num2;
if (num4 < 0) 
{
	 calc3 = ((int) num4/100 %10) * -1;
}
else
{
     calc3 = ((int) num4/100) %10;
}
calc4 = num2/num3;
calc5 = num3 * num4;
calc6 = num3/num1;
calc7 = num1 + num2 + num3 + num4;
calc8 = calc7 / 4;
return calc1, calc2, calc3, calc4, calc5, calc6, calc7, calc8;
}

void printTable (int num1, int num2, int num3, float num4, int calc1, int calc2, 
int calc3, int calc4, double calc5, double calc6, float calc7, float calc8)
{

printf("\n Description :-28%14.2d\n", "Data");
printf("\n Input 1 (int) :-28%14.2d\n", num1 );
printf("\n Input 2 (int) :-28%14.2d\n", num2 );
printf("\n Input 3 (int) :-28%14.2d\n", num3 );
printf("\n Input 4 (float) :-28%14.2f\n", num4 );
printf("\n Input 1 + Input 3 (int) :-28%14.2d\n", calc1 );
printf("\n Input 1 * Input 2 (int) :-28%14.2d\n", calc2 );
printf("\n Hundreds Digit of Input 4 :-28%14.2d\n", calc3 );
if (num3 !=0)
	printf("%-28s%14d\n","input 2 / Input 3 (int)", calc4);
else
	printf("%-28s%14s\n","input 2 / input 3 (int)", "DIV/0");
printf("\n Input 2 / Input 3 (int) :-28%14.2f\n", calc4 );
printf("\n Input 3 * Input 4 (double) :-28%14.2f\n", calc5 );
if (num3 !=0)
	printf("%-28s%14d\n","input 3 / Input 1 (int)", calc6);
else
	printf("%-28s%14s\n","input 3 / input 1 (int)", "DIV/0");
printf("\n Input 3 / Input 1 (double) :-28%14.2f\n", calc6 );
printf("\n Sum of the input (float) :-28%14.2f\n", calc7 );
printf("\n Average of the input (float) :-28%14.2f\n", calc8 );

return ; 
}

At lines 20-27, you've already declared the return-types and argument types of the functions (up at the very top of your program). Now you just need to call the functions and capture the return types, for example:

greeting();
getInput();
int result = calculate(num1, num2, num3, num4);
...

Also, your getInput() function doesn't do anything useful, because you re-declare the four values locally (within the function) and then read them in. The local variables are destroyed when the function returns. Instead, try:

void getInput(int &num1, int &num2, int &num3, float &num4);
    // return type is void, if the function doesn't return a value
    // note the '&' on each argument ... passing references (rather than copies)
    // means that changes made inside the function (like inputting values) will
    // be saved in the original variables, not the copies

...
getInput(num1, num2, num3, num4);
    // no '&' here, that's just how the function is declared

...
void getInput(int &num1, int &num2, int &num2, float &num4)
{
    // parameters are declared above, no local variables needed
    // also, get in the habit of using consistent indentation, it will make your
    // code more readable for you and for others
    printf("Enter three integers and a floating point number then press enter: ");
    scanf("%d%d%d%g", &num1, &num2, &num3, &num4);
        // no spaces needed in the format-string, scanf() will automatically
        // skip over spaces in the input
        // also note the '%g' format for the float variable
    return;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.