C programming help

i need help with a assignment for a c programming class , i cant seem to get this code to work and i’m having a hard understanding the process of putting the code together. i get errors every time i run it . I’m very new to this and have limited knowledge any help is appreciated. The book we have “c how to program 8th edition” isn’t very good at explaining how to do this. any resources that can be recommend to help me with c programming would be awesome as well. thanks
heres the code. it needs to print out the average , sum , product and smallest and largest number of any 3 numbers.

/* a c-program to print the sum , product, average , largest , smallest number of the three different numbers given is*/
   /*header-file notation*/
   #include <stdio.h>
/* function main for program execution*/
   int main ()
/* statement begins*/
   {
    /*variables are declared*/
    int integer1 , integer2 , integer3 , sum,average,product,smallest,largest;
    /* print the integers*/
    printf("input three different integers: \n ");
    /* reads the values of integers*/
    scanf("%d%d%d ",&integer1 ,&integer2 ,&integer3 ) ;
    /* expression assigning the total to sum */
    sum = integer1+integer2+integer3 ;
    /* prints the sum */
    printf("sum is %d\n" , sum ) ;
    /*assign total to sum */
    average =(integer1+ integer2+ integer3) /3 ;
    /*prints the average*/
    printf(" average is %d\n", average ) ;
    /*assign the total to product*/
    product = integer1 * integer2 * integer3 ;
    /*prints the product*/
    printf("product is %d\n " , product) ;
    /*comparison to the two numbers*/
    smallest = integer1 ;
        if(integer2 < smallest)
            smallest=integer2 ;
        if ( integer3< smallest )
            smallest=integer3 ;
    /*prints the smallest number*/
    printf( "smallest is %d\n " , smallest ) ;
    /* comparison to the two numbers*/
    largest = integer1 ;
    /*if statement is used*/
        if(integer2 > largest )
            largest = integer2 ;
    /*if statement is used*/
        if (integer3> largest)
            largest = integer3 ;
    /*prints the largest number*/
    printf("largest is %d\n" , largest) ;
    /*indicates the program executes successfully*/
    return 0
;
}

You have a few issues, namely with your commenting the code and your use of scanf().

For simplicity, put // at the start of the line where you want a comment. You are trying to use /, which is not a comment character. Also, be careful with /* ... */. You have your sum code trapped inside a comment. Edit: The issue with your comments was due to your copy and paste without using ```. I still recommend // over /* ... */ though.

Second, you are confusing scanf(). Look at this discussion for clarification, but you want to be very careful when reading in multiple values into scanf().

  1. You want a space between the %d representing the numbers given by the user.
  2. You do not want a space at the end of your string inside of scanf().

(Side note, it’s generally recommended to use fgets() instead of scanf. I bet you’ll get there in your class eventually.)

Lastly, I would recommend you put some white space between parts of your code. Hit enter a few time to separate the different things you are doing!!!

// Calculate sum
sum = num1 + num2 + num3;
// Print sum
printf("The sum is %d\n", sum);

// Calculate wrong sum
wrong_sum = num1 + num2 - num3;
// Print wrong sum
printf("The sum is not %d", wrong_sum);

This is much easier to read!

Note, please use ``` before and after a chunk of code on the forum! It helps readability.

As for help, asking questions here is reasonable, but generally my favorite “book” is Google. I code C as my job, and I Google questions all the time. If you aren’t sure what to Google, or how to understand the results you get, ask here!

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor ( </> ) will also add backticks around text.
Note: Backticks are not single quotes

little question
the image that you’ve attached to the message doesn’t seem to load
or is it just for me

Hi and welcome to the forum.

This post has had no replies in 9 months. We have changed the demo image since this reply was made.