0

I been having issues having my C code work. I have 1 warning, which states Warning: too many arguments for format. I am a beginner in C so I haven't encountered this issue yet. Any ideas on how to fix it and I cannot use conditions as I am in the beginning segment of my course learning from the start. I just need to know what I did wrong so I can fix the issue. Here's the code below:

#include <stdio.h>

int main() {
    float firstNumber, secondNumber, thirdNumber;
    float fourthNumber, fifthNumber;

    float sumAverage1 = (firstNumber+secondNumber+thirdNumber);
    float sumAverage2 = (fourthNumber+fifthNumber);


    long a = 1000000000;
    long b = 1250000000;
    long c = 1500000000;
    long d = 1750000000;
    long e = 2000000000;

        printf("A is %li\n", a);
        printf("B is %li\n", b);
        printf("C is %li\n", c);
        printf("D is %li\n", d);
        printf("E is %li\n", e);

        printf("Enter 5 Random numbers and guess what the total will be summed up when program runs.\n");
        printf("You cannot enter a decimal integer and enter numbers below 100.\n");
            scanf("%f", &firstNumber);
            scanf("%f",&secondNumber);
            scanf("%f",&thirdNumber);
            scanf("%f",&fourthNumber);
            scanf("%f",&fifthNumber);

            printf("Your numbers average out to:\n", sumAverage1+sumAverage2/5);

    system("pause");
return 0;
}
  • 3
    In the last `printf` you have forgotten to put a format specifier for the number (`%f` I guess...). – Eugene Sh. May 24 '17 at 20:53
  • 2
    forgot to add #include at top when I added system pause. – Matthew Stone May 24 '17 at 20:54
  • 1
    You also calculate the sums before getting any input. – JJJ May 24 '17 at 20:55
  • Thanks man. I didn't notice it. Stayed up late last night, brain dead haha. Thank you and I will vote up when it allows. – Matthew Stone May 24 '17 at 20:56
  • 1
    The code is still not functional. I moved: scanf("%f", &firstNumber); scanf("%f",&secondNumber); scanf("%f",&thirdNumber); scanf("%f",&fourthNumber); scanf("%f",&fifthNumber); float sumAverage1 = (firstNumber+secondNumber+thirdNumber); float sumAverage2 = (fourthNumber+fifthNumber); printf("Your numbers average out to:%f\n", (sumAverage1+sumAverage2)/5); – Matthew Stone May 24 '17 at 20:59
  • Save time. Enable all compiler warnings. – chux - Reinstate Monica May 25 '17 at 00:37

3 Answers3

1

The line:

 printf("Your numbers average out to:\n", sumAverage1+sumAverage2/5);

Has an argument but no format specifier. Also, that expression is unparenthesized; the division has higher precedence than the addition, so what you're calculating is sumAverage1+(sumAverage2/5), which is integer division, which is probably not what you want.

What you probably want is:

printf("Your numbers average out to: %f\n", (double)(sumAverage1+sumAverage2)/5.0);
Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
0

You need to change the printf format specifier, but your scanf does not capture the extra dangling newline. You need to either clear the buffer, fflush(stdin) after each scanf() or you need an extra scanf("%c") to get rid of the newline character.

See scanf() leaves the new line char in buffer?

Felix Guo
  • 2,700
  • 14
  • 20
  • `scanf("%c")` gets the next character after the number, which _might_ be a newline. It might not. It is simple the next character. `fflush(stdin)` is a non-portable way to empty `stdin`. "scanf does not capture the extra dangling newline." misleads as `scanf("%f",&secondNumber);` will consume any prior white-space first, including the previous line's leftover newline. – chux - Reinstate Monica May 25 '17 at 11:47
0

Here this will solve all your problem.

#include <stdio.h>
#include <stdlib.h>
int main() {
float firstNumber, secondNumber, thirdNumber,sumAverage1;
float fourthNumber, fifthNumber,sumAverage2;
long a = 1000000000;
long b = 1250000000;
long c = 1500000000;
long d = 1750000000;
long e = 2000000000;
printf("Enter 5 Random numbers and guess what the total will be summed up when program runs.\n");
printf("You cannot enter a decimal integer and enter numbers below 100.\n");
scanf("%f",&firstNumber);
scanf("%f",&secondNumber);
scanf("%f",&thirdNumber);
scanf("%f",&fourthNumber);
scanf("%f",&fifthNumber);

sumAverage1 = (firstNumber+secondNumber+thirdNumber);
sumAverage2 = (fourthNumber+fifthNumber);

    printf("A is %li\n", a);
    printf("B is %li\n", b);
    printf("C is %li\n", c);
    printf("D is %li\n", d);
    printf("E is %li\n", e);
        printf("Your numbers average out to:%f\n", (sumAverage1+sumAverage2)/5);

system("pause");
return 0;
}

I ran this on my Visual Studio and it works just fine. Hope it Solves your Problem.

Vishwajeet Vishu
  • 492
  • 3
  • 16