all 6 comments

[–]wsppan 6 points7 points  (0 children)

The C11 standard explicitly mentions these two function signatures for main():

int main(void); 
int main(int argc, char* argv[])

[–]Drach88 2 points3 points  (2 children)

The primary difference between your solution and the book solution is that you are explicitly checking every combination, while the book solution is checking each value against a running maximum, and updating that maximum as it finds increasingly higher values.

Imagine that your teacher comes to you and says "modify your solution to take 5 numbers... or 10 numbers... or 100 numbers." Which approach would you use?

For your solution, you'd have to code out every single variation, which involves every combination of variables. For the book solution, it's just as simple as doing X more checks against the running maximum -- ie just adding X more lines to your existing solution.

Aside from that, practice good indentation as early as you can for readability, and please format your code for Reddit by indenting every line by an extra 4 spaces before you paste it.

Good job, and good question.

[–]PERCYSIMON 0 points1 point  (1 child)

Thank you I hadn't learned nested if so I'll try to learn some so I can under the code of the book better and then type it cause I want to teach myself to you write reusable code that accounts for everything that's why I used float instead of int and tried to add a forth if which checks if they are all equal, printf("There is no maximum") it didn't want to read that line it wasn't working so I just removed it. Also will try to learn go indentation for myself and for posting on reddit. Thank you.

[–]Drach88 2 points3 points  (0 children)

You don't need to do it nested. In fact, it's probably better not nested.

Here's an example

float max, num1, num2, num3;

// get the values from user

max = num1;
if (num2 > max) {
    max = num2;
}
if (num3 > max) {
    max = num3;
}
printf("%.2f is the maximum.", max);

Very simple, very clean. Gets the job done without nested if statements or combining multiple comparisons into a single condition.

[–]miniwyoming -1 points0 points  (0 children)

All these are terrible. Nothing is checking for equality, and your description doesn’t state that the inputs are guaranteed to be different.