Results 1 to 3 of 3

Thread: If problem

  1. #1
    Join Date
    Sep 2012
    Beans
    57

    If problem

    I have a problem with my code because it doesn't work as I want to.
    Here's the code.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
    
        int st, nd;
        printf("Hello!\a");
        getchar();
        printf("I'm the manudo's (iMnd) multiplicator 2.0\n");
        getchar();
        system("clear");
        printf("Enter the first number \n");
        scanf("%d", &st);
        printf("0K, now give me the second number \n");
        scanf("%d", &nd);
        if (st || nd == 0) printf("Any product of 0 is \"0\"\n");
        else printf("The result of the multiplication is \"%d\"\n", st*nd);
        return 0;
    }
    This code is for the multiplication of two numbers, but there's an if that has to check if any of the numbers that the user entered is 0, if yes, program return a message saying that any product of 0 is 0 and if it's not, return the result message. Well that's it has to do.

    The problem is if I put 0 and 2 it shows the result and the else message, and for this case I want to the program shows the else message ONLY.

    Here's an screenshot of the result: http://s13.postimage.org/j024g6yyd/screenshot.png

    Please be patient for my English and my "n00bness". Thanks in advance!

    PS: I use Ubuntu 12.04 and Anjuta to compile. Dev-C++ in Windows return with the same problem.

  2. #2
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: If problem

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
    
        int st, nd;
        printf("Hello!\a");
        getchar();
        printf("I'm the manudo's (iMnd) multiplicator 2.0\n");
        getchar();
        system("clear");
        printf("Enter the first number \n");
        scanf("%d", &st);
        printf("0K, now give me the second number \n");
        scanf("%d", &nd);
        if (st == 0 || nd == 0) {
            printf("Any product of 0 is \"0\"\n");
        } else {
            printf("The result of the multiplication is \"%d\"\n", st*nd);
        }
        return 0;
    }
    「明後日の夕方には帰ってるからね。」


  3. #3
    Join Date
    Sep 2012
    Beans
    57

    Re: If problem

    Why the void in int main()?

    Whatever, really thank you bro.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •