Question

In: Computer Science

IN C This assignment is to write a program that will prompt the user to enter...

IN C

This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) 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 a previous assignment. 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 two arguments. One argument is the number of characters and the other argument is the character to draw. The function will use a for loop to draw that number of characters on the screen and then will print a newline.

Solutions

Expert Solution

#include<stdio.h>

#include <stdlib.h>

void draw_line(int v,char ch)                // draw_line function definition with two arguments- no. of characters and the chracter to draw

{

    int i;

    for(i=0;i<v;i++)

        printf("%c",ch );                     // for loop to draw the character desired number of times on the screen

    printf("\n");                             // printing the new line

}

int main(){                                  // main function definition

    char ch;

    int v;

    do{

        scanf("%c%d",&ch,&v);               // taking the character and the no. of character to draw as input from the user

        if(v<1||v>79)                      // checking whether the number is in the range or not

        {

            printf("The number must be in the range 1 to 79(both included) : ");     

            fflush(stdin);                  // clearing the keyboard buffer

            continue;

        }

        draw_line(v,ch);                    // calling the draw_line function

        break;                              // do-while loop breaks when we get the desired no.

    }while(1);

    return 0;

}


Related Solutions

Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Assignment in C: prompt the user to enter secret message that is terminated by presding Enter....
Assignment in C: prompt the user to enter secret message that is terminated by presding Enter. You can assume that the the length of this message will be less than 100 characters. You will then parae this message, character by character, converting them to lower case, and find corresponding characters in the words found in the key text word array. Once a character match is found, you will write the index of the word and the index of the character...
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in...
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in a number greater than or equal to zero and less than or equal to 100. If they do not you should alert them and end the program. Next, determine the letter grade associated with the number. For example, A is any grade between 90 and 100. Report the letter grade to the user.
A. Write a program 1. Prompt the user to enter a positive integer n and read...
A. Write a program 1. Prompt the user to enter a positive integer n and read in the input. 2. Print out n of Z shape of size n X n side by side which made up of *. B. Write a C++ program that 1. Prompt user to enter an odd integer and read in the value to n. 2. Terminate the program if n is not odd. 3. Print out a cross shape of size n X n...
(b) You will write a program that will do the following: prompt the user enter characters...
(b) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘Q’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘Q’. Example input mJ0*5/]+x1@3qcxQ The ‘Q’ should be included when computing the statistics properties of the input. Since characters are integers...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
Program IN C Prompt the user to enter month number and year. Retain an appropriate response...
Program IN C Prompt the user to enter month number and year. Retain an appropriate response for invalid month numbers, but don’t worry about validity of year. 2.Determine the number of days in the month entered (ignore leap years). 3.Use the answer to step 2 in one FOR-LOOP to ask the user to enter a FAHRENHEIT temperature (integer or floating) for each day of the month utilizing a prompt that includes the DATE. a. Prompt the user to enter the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT