Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

+2 votes
asked Oct 2 by Lexus Guevara (200 points)
closed Oct 3 by Admin

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!

closed with the note: answered

1 Answer

+1 vote
answered Oct 3 by Julian (460 points)
selected Oct 3 by Lexus Guevara
 
Best answer
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 by Lexus Guevara (200 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
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...