Thread: for loops

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    6

    for loops

    I can not figure out how to set my for loop up so that it will relay back whether or not the number entered by the user is perfect, deficient, or abundant. This is what I have so far. I know it needs a lot of work but I am stuck...

    # include <stdio.h>
    main()
    {
    int num=0, count=1, sum=0;
    char perfect, abundant, deficient;

    perfect==((count % num) && (count==sum));
    abundant==((count % num) && (count < sum));
    deficient==((count % num) && (count > sum));

    printf("This program will ask you to enter some numbers.\n");
    printf("Number Type\n");
    printf("------ ----\n");

    for(count=1; count <= 20; count++)
    printf("%d ",count);
    scanf("%d", &count);

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Don't know exactly what you mean. But I'll give it a try: you're for-loop should contain something like this.

    Code:
    scanf ("%d", &num);
    
    perfect = (count % num) && (count==sum); 
    abundant = (count % num) && (count < sum); 
    deficient = (count % num) && (count > sum);
    
    if (perfect)
        printf ("num is perfect\n");
    else if (abundant)
        printf ("num is abundant\n");
    else /* deficient == TRUE */
        printf ("num is deficient\n");
    Ofcourse the calculation of perfect, abundant and deficient is not needed, it could be done in the if-condition. This would save both space and time.

Popular pages Recent additions subscribe to a feed