# I have a problem about the answers of my computation, I don't know if it is because of the code or compiler

closed Oct 3, 2021

When you try to input this stuff into a C compiler, the last answer printf("\nTotal of illiterate men is %d and women is %d. ", illiterateMen, illiterateWomen); doesn't really define the true answer instead, it put some random numbers. I tried to use the unsigned long int and also the float and doubles, but still, it is just random numbers.

#include <stdio.h>

int main()
{
unsigned int men, women, literatePeople, literateMen, literateWomen, illiterateMen, illiterateWomen, illiteratePeople;

men = 80000 * 0.52;
women = 80000 - men;
literateMen = 80000 * 0.35;
literateWomen = literatePeople - literateMen;
literatePeople = 80000 * 0.48;
illiteratePeople = 80000 - literatePeople;
illiterateMen = men - literateMen;
illiterateWomen = women - literateWomen;

printf("Total of men in the town : %d", men);
printf("\nTotal of literate people : %d", literatePeople);
printf("\nTotal of literate men : %d", literateMen);
printf("\nTotal of women : %d", women);
printf("\nTotal of illiterate men is %d and women is %d. ", illiterateMen, illiterateWomen);

return 0;
}

Output:

Total of illiterate men is 13600 and women is 44673.

the italized one is just a random 5 digit numbers but usually starts with 44.

I hope you can help me, it will make a lot of change for my activity at school. Thank you!

+1 vote
answered Oct 3, 2021 by (460 points)
selected Oct 3, 2021 by Lexus Guevara

You are using literatePeople before giving it a value, you should cut literateWomen = literatePeople - literateMen; and paste it after literatePeople = 80000 * 0.48; it will look like this:

#include <stdio.h>

int main()
{
unsigned int men, women, literatePeople, literateMen, literateWomen, illiterateMen, illiterateWomen, illiteratePeople;

men = 80000 * 0.52;
women = 80000 - men;
literateMen = 80000 * 0.35;
literatePeople = 80000 * 0.48;
literateWomen = literatePeople - literateMen;
illiteratePeople = 80000 - literatePeople;
illiterateMen = men - literateMen;
illiterateWomen = women - literateWomen;

printf("Total of men in the town : %d", men);
printf("\nTotal of literate people : %d", literatePeople);
printf("\nTotal of literate men : %d", literateMen);
printf("\nTotal of women : %d", women);
printf("\nTotal of illiterate men is %d and women is %d. ", illiterateMen, illiterateWomen);

return 0;
}
commented Oct 3, 2021 by (590 points)
thank you so much, I thought it will not affect the values if I arrange it just like that, but it really need to be like step by step or in order to make it possible