-3

This is my code for a fizzbuzz function. With 'int num' that prompts the user for an integer, then prints all of the numbers from one to that integer.

void fizzbuzz(int num) {
    int i;
    printf("Max value? %d\n", num);
    for(i = 1; i <= num; i++) {
        if (i % 3 == 0)
            printf("Fizz ");
        if (i % 5 == 0)
            printf("Buzz ");
        if ((i % 3 != 0) && (i % 5 != 0))
            printf("%d ", i);
        if (i % 20 == 0)
            printf("\n");
    }
}

int main() {
    fizzbuzz(100);
}

However I get a too few arguments to function fizzbuzz(); Im submitting this through codestepbystep but on atom my code runs with no problem. What's the problem with my program, i feel like its a very simple fix but I could not find anything on the internet.

dreamcrash
  • 47,137
  • 25
  • 94
  • 117
Eric
  • 1
  • The code you posted seems to have no way to cause the error you half-quoted. Is this the exact code you used to get that error? What compiler does "codestepbystep" use? What is the exact error that it reports? – underscore_d Feb 04 '21 at 11:46
  • as @underscore_d said, maybe codestepbystep uses its own main function where it calls fizzbuzz with no args? something like that? – Spoody Feb 04 '21 at 11:47
  • 2
    `too few arguments to function fizzbuzz();`..that's fishy, as your code has `fizzbuzz(100);` – Sourav Ghosh Feb 04 '21 at 11:47
  • 1
    The code you show here is fine. The problem is with "codestepbystep" whatever that is. Show is the "codestepbystep" so we can check – Jabberwocky Feb 04 '21 at 11:47
  • 1
    The exact error message is: Error emitted from internal testing code. This error is occurring when our internal testing code is trying to call your code. If you see this, it may mean that you have the wrong header for your solution, or a mismatched { } ( ) brace. too few arguments to function 'fizzbuzz' fizzbuzz(); ^ – Eric Feb 04 '21 at 11:48
  • I submitted my code without my main() to call it and I get the error message, I understand that codestepbystep uses a different compiler but im new to coding so I do not know what changes i would need to make – Eric Feb 04 '21 at 11:51
  • 3
    I think maybe you're supposed to define `void fizzbuzz(void);` and input the number inside the function. Apparently the "internal testing code" has the statement `fizzbuzz();` which does not work with your definiton of the function... and would result in that diagnostic (calling a function expected to take 1 argument with none). – pmg Feb 04 '21 at 11:52
  • Hint: Why do you take an argument to the function when the function is supposed to promp the user for a number? – klutt Feb 04 '21 at 11:59
  • Source problem (???) https://www.codestepbystep.com/problem/view/c/loops/fizzbuzz – pmg Feb 04 '21 at 12:04
  • 1
    Voting to close this as a typo – klutt Feb 04 '21 at 12:13
  • I am surprise that there is a tag named fizzbuzz – dreamcrash Feb 04 '21 at 12:38

1 Answers1

3

The test code from the website you’re using is expecting the function signature void fizzbuzz(void), and is calling the function as fizzbuzz().

Remove the parameter, as it is unused/overwritten by the function anyway.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214