Hello everyone, I'm new here.

I was working on a homework problem for a basic intro to C class and I'm getting a syntax error for an if statement and I have no idea why it's popping up.

#include <stdio.h>

// Function Declarations
int Sum (int x);
float Average (float x, 
               float RC);
void Print (int sum,
            int largest,
            int smallest,
            float average,
            int lessthan,
            int between);


int main (void)
{
    // Local Declarations
    int x;
    int sum;
    int largest = -100;
    int smallest = 99998;
    float average;
    int lessthan;
    int between;
    int RC;
    
    // Statements
   printf ("Enter numbers with <return> (99999 to stop): ");
   while ((RC = scanf ("%d", &x)) != 99999)
          {
              if (x < 20)
                 lessthan = 1;
              else 
                 lessthan = 0;
              if (10 <= x && x <= 90)
                 between = 1;
              else
                  between = 0;
              if (x > largest)
                 largest = x;
              if (x < smallest)
                 smallest = x;    
          sum = Sum (x);
          average = Average (x, RC);
          }
          
          Print (sum, largest, smallest, average, lessthan, between);
    
    //int temp;
    scanf("%d");  //stop screen
   
    return 0;
    
} // main

/* ===============Sum===============
   This function makes a series of calculations.
   Pre Nothing
   Post Reads x
   Returns sum
*/

int Sum (int x)

{
//Local Declarations
int sum = 0;

//Statements
sum += x;


return sum;

} //Sum


/* ===============Average===============
   This function makes a series of calculations.
   Pre Nothing
   Post Reads x
   Returns average
*/

float Average (float x, float RC)

{
//Local Declarations
float average = 0;

//Statements
average += x / RC;


return average;

} //average


/* ===============Print===============
   This function makes a series of calculations.
   Pre Nothing
   Post Reads sum, largest, smallest, average, lessthan, between
   Returns Nothing
*/

void Print (int sum, int largest, int smallest, float average, int lessthan,
int between)

{
//Local Declarations


//Statements
//printf ("The number of integers is: 
printf ("The sum of the integers is: %8.2d\n", sum);
printf ("The average of the integers is: %8.2f\n", average); 
printf ("The smallest integer is: %8.2d\n", largest);
printf ("The largest integer is: %8.2d", smallest);
    if lessthan = 0
       printf ("At least on number was < 20: True\n");
    else
       printf ("At least on number was < 20: False\n");
    if between = 0
       printf ("All numbers were (10 <= x >= 90): True\n");
    else
       printf ("All numbers were (10 <= x >= 90): False\n");


return ;

} //Print

I put in the whole code just encase but the problem is with my first if statement in my Print function (line 120).

I tried switching the if statements to make sure that the syntax error wasn't with the if statement itself and when I switched them the error remained on line 120. I also attempted double slashing the previous lines out of the code to try to pin point the problem, but nothing seems to stop the error from appearing.

I know other parts of the program are probably a mess right now, but that's mostly because I can't actually run it and experiment with it because of this error. So just ignore any other little things you see, I'll fix them up later.

Thanks in advanced for any and all help.

Comments
your first post ever and you submitted formatted, indented code. my faith in humanity is somewhat restored. thanks :)

Two things wrong with the if statement on lines 120 and 124
1) if statements must have ( and ). e.g. if( condition ) 2) = is an assignment operator, == is a boolean logic operator. You want to use == in if statements

Edited 7 Years Ago by Ancient Dragon: n/a

Two things wrong with the if statement on lines 120 and 124
1) if statements must have ( and ). e.g. if( condition ) 2) = is an assignment operator, == is a boolean logic operator. You want to use == in if statements

Thanks for that. I figured it was probably something simple that I overlooked, but I couldn't figure out what it was for the life of me.
Thanks for the help.

This question has already been answered. Start a new discussion instead.