Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C. Your program should print a message indicating that the number must be

ID: 670632 • Letter: U

Question

Using C. Your program should print a message indicating that the number must be in the range 1 to 79 if the user enters a number outside of that range. Your program should continue this behavior until you have received an appropriate integer. Use a loop to trap the user until you get the value that you want as you did in daily9. You should also clear the keyboard buffer after each scanf so that the user can type characters or digits in their response. Once you have a number in the appropriate range call a function that you write called draw_line that takes one argument of type integer and will use a loop to draw that number of asterisks on the screen and then will print a newline.

Output:

Please enter the number of asterisks you want in your line: -4

I'm sorry, that number is unrecognized or out of range, try [1-79]: why?

I'm sorry, that number is unrecognized or out of range, try [1-79]: ok

I'm sorry, that number is unrecognized or out of range, try [1-79]: 7

*******

Explanation / Answer

#include<stdio.h>
int main()
{
   int daily9;
   printf("Please enter the number of asterisks you want in your line: ");
   while(1)
   {
      
       int i=1;
       scanf("%d",&daily9);
       if(daily9>=1 && daily9<=79)
       {
           for( i=1;i<=daily9;i++)
               printf("*");
           break;
       }
       else
       {
           printf(" I'm sorry, that number is unrecognized or out of range, try [1-79]: why?");
           printf(" I'm sorry, that number is unrecognized or out of range, try [1-79]: ok");
           printf(" I'm sorry, that number is unrecognized or out of range, try [1-79]: 7") ;
           fflush(stdin);
       }
   }
  
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote