Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

FuzzBizzNezz function

Hi everyone!

I wrote a program in C language that took three int inputs, Fuzz, Bizz and Nezz, the consoles is printing numbers from 1 to "Nezz" and for the multiples of Fuzz is gonna print Fuzz instead of the number, and for the multiples of Bizz is gonna print Bizz instead of the number, now I´ve been asked to do this as a function, so I can call it in main() whenever I want but I´m a bit confused

How do I return multiple values from a function? Do I have to set up a loop within the function?

heres the program;

include <stdio.h>

int main() {

int n, f, b;
int x;

printf("Enter Nezz Number\n");
scanf("%d", &n);


printf("Enter Fuzz Number\n");
scanf("%d", &f);


printf("Enter Bizz Number\n");
scanf("%d", &b);


for (x = 1; x <= n; x++) {

    if (x % f == 0 & x % b == 0) {

        printf("FuzzBizz\n");

    }

    else if (x % f == 0) {

        printf("Fuzz\n");

    } else if (x % b == 0)  {

        printf("Bizz\n");

    } else {

        printf("%d\n", x);

    }
}

}

1 Answer

In order to return multiple values in C, you would need to either use pointers or setup a struct with those two data structures. Here's a post on stack overflow that may help with what you're trying to accomplish.

http://stackoverflow.com/questions/2620146/how-do-i-return-multiple-values-from-a-function-in-c