Thread: Finding the nearest even integer that's greater than the inputted number.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    6

    Finding the nearest even integer that's greater than the inputted number.

    For the input of: 4.1, the output is supposed to be: 6. Please help, it seems that the output of the program that i wrote is just random.
    Edit:
    Code:
     
    #include <stdio.h>
    
    
    int main(void) {
      while (1) {
        printf("Please enter a number:\n");
        double number0;
           scanf("%lf",&number0);
        int number,check1,check2,result1,result2;
        number = (int)number0;
        result1 = number++;
        result2 = number+2;
        check1 = result1%2;
        check2 = result2%2;
        if (check1==0)
            printf("The nearest even integer that's greater than the entered number = %i. \n",result1);
            else
            printf ("The nearest even integer that's greater than the entered number = %i. \n", result2); 
      }
      return 0; }
    Attached Images Attached Images Finding the nearest even integer that's greater than the inputted number.-cantsolve-jpg 
    Last edited by Null_Void; 04-07-2020 at 07:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 11-11-2017, 01:26 AM
  2. Rounding float to nearest integer
    By xArt in forum C Programming
    Replies: 2
    Last Post: 01-31-2017, 07:05 AM
  3. Issue finding greater fraction
    By hss1194 in forum C++ Programming
    Replies: 3
    Last Post: 12-08-2012, 06:28 AM
  4. Replies: 4
    Last Post: 02-11-2011, 03:29 PM
  5. finding nearest neighbour distance
    By zesty in forum C Programming
    Replies: 21
    Last Post: 12-02-2009, 05:20 AM

Tags for this Thread