简体   繁体   中英

i was also told to use: int get_input(char message[]) in my code but i don't know how to use it

i was given an assignment to write a code prompting the user to input an even number (and to continue prompting if the number was not even) and after the even number is input prompt the user to input an odd number. I was also told to use: int get_input(char message[]) in my code but i don't know where and how to use it. this is the code below.

            ```
            #include<stdio.h>
            int main(int argc,char**argv)
 {
          int num_odd;
          int check_even;


           printf("Enter an even number: ");
           scanf("%d",&check_even);

  do{

            if (check_even%2==0)
    {
             printf("Ok thanks! Now enter an odd number\n");
              scanf ("%d",&num_odd);
    {
           break;
    }
    }

        else
    {
        printf("That is not even enter an even number. Enter an even number:\n");
        scanf("%d",&check_even);
    } }while ('check_even%2!=0' && 'check_even%2==0');

    do
    {
     if (num_odd%2!=0)
      {
   printf("**Thanks bye!**");
   {
       break;
   }
   }
       else
   {
       printf("That is not an odd number. Enter an odd number.\n");
       scanf("%d",&num_odd);
   }

    }while ('num_odd%2==0' && 'num_odd%2!=0');


     }
     ```

i was also told to use: int get_input(char message[]) in my code but i don't know how to use it

The name, parameter and return type of this function as well as the problem description indicate that you are supposed to use it for prompting and inputting the number, ie rather than

           printf("Enter an even number: ");
           scanf("%d",&check_even);

you shall use

           check_even = get_input("Enter an even number: ");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM