Thread: Please help me about my project

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    4

    Please help me about my project

    I'm a newbie here, Im a college student from Philippines. i would just like to ask a way to code the given problem. Where a program that when you enter any integer, it will display whether it is negative or positive then terminate the program when you enter 0 using do/while loop in c language. Please someone help me about this one. I already made to display the positive or negative but it always terminate after that. Thankyou

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    We don't program your project. You need to show us your attempt at writing the code, then we can comment on your attempt.

    Please also read the FAQs at the top of the forum.

  3. #3
    Registered User
    Join Date
    Oct 2019
    Posts
    4

    here's one of my project

    8 positive or negative.cpp8 positive or negative.cpp
    Quote Originally Posted by rstanley View Post
    We don't program your project. You need to show us your attempt at writing the code, then we can comment on your attempt.

    Please also read the FAQs at the top of the forum.

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Please post all cde in [CODE ] blocks, as instructed in the FAQ's.
    Code:
    #include<stdio.h>
    #include<conio.h>
    int num,repeat;
    main()
    {   
        printf("Enter any number: ");
        scanf("%d", &num);
        do
        {
        if(num > 0)
        {
            printf("Number is POSITIVE");
        }
        if(num < 0)
        {
            printf("Number is NEGATIVE");
        }
        if(num == 0)
        {
            printf("Number is ZERO");
        }
    }
        while(num=='0');
        repeat=1;
    getch();
    }
    First, you should check the result from scanf() to insure that a valid number has been entered.

    Next, you are comparing num against the character '0, NOT the VALUE 0 (Zero)
    Code:
    while(num == 0);
    // NOT
    while(num == '0');
    Also, make your variables local, and always inisitialize them to zero or some other specific value.

    Last, please don't use conio.h functions. They are non-standard C and only available in Windows compilers.

  5. #5
    Registered User
    Join Date
    Oct 2019
    Posts
    4
    Thankyou sir!

  6. #6
    Registered User
    Join Date
    Oct 2019
    Posts
    4
    sir conio.h is what our professor told us to use so if he check it. He must see it in header

  7. #7
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by kokoy View Post
    sir conio.h is what our professor told us to use so if he check it. He must see it in header
    I suggest you find a new teacher who knows what he's doing then cause your current one clearly doesn't

  8. #8
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Quote Originally Posted by kokoy View Post
    sir conio.h is what our professor told us to use so if he check it. He must see it in header
    Then you will need to use conio.h for this course, or at least, this assignment. However, after the course, I would strongly recommend to not use it in the future.

    I would be happy to discuss this privately with your professor, to explain the importance of only using Standard C functions, and avoiding any Windows based extensions to the language.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 08-02-2013, 06:45 PM
  2. Replies: 5
    Last Post: 02-23-2013, 03:37 PM
  3. Classes Project (Not class project)
    By adam.morin in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2011, 01:48 AM
  4. Paid project - The Free Marketing Project
    By sharefree in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 10-27-2010, 02:15 PM
  5. your 11th & 12th grade c++ project or similar project
    By sleepyheadtony in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-13-2002, 05:14 PM

Tags for this Thread