Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Counting how many dozen in a number and also count its extra amount?

How do i make this program counts how many dozen in a number and also count its extra amount?
This is what only I came up

#include<stdio.h>

int main()

{

float number, dozen;

printf("Please Enter any integer Value : ");

scanf("%f", &number);

dozen = number / 12;

printf("dozen of a given number %.2f is  =  %.2f", number, dozen);

return 0;

}

I dont know how i will get to count the dozen in a number, for example there is 45, i need to get 3 dozen and the extra will be 9.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You prompt for an integer but then use floats. You already had the correct dozen calculation and just miss the modulo operator %. Reformatted code for readability.

#include <stdio.h>

int main() {
    printf("Please Enter any integer Value : ");
    int number;
    scanf("%d", &number);
    printf("dozen of a given number %d is %d with remainder %d\n",
        number,
        number / 12,
        number % 12
    );
    return 0;
}

and example execution:

Please Enter any integer Value : 14
dozen of a given number 14 is 1 with remainder 2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading