Preview:
#include <stdio.h>

int calculate_pizza_share(int number_of_people);

int main(void)
{
    int number_of_people;

    // Prompt the user for input
    printf("How many people? \n");
    scanf("%d", &number_of_people);

    // Calculate the pizza share
    int slices_per_person = calculate_pizza_share(number_of_people);

    // Output the result
    if (slices_per_person == -1) 
    {
        printf("Error\n");
    } 

	else 
    {
        printf("%d people get %d slice(s) each.\n", number_of_people, slices_per_person);
    }

    return 0;
}

int calculate_pizza_share(int number_of_people)
{
    if (number_of_people <= 0) 
    {
        return -1; // Error for non-positive number of people
        
    }

    int total_slices = 8; // Total slices in a pizza

    return total_slices / number_of_people;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter