Question

Please write individual functions solving each of the following problems: Print your name Print numbers 1 → 10 Print numbers N → M, where N and M are parameters to the function .Calculate and return a base B to an exponent E. B and E should be parameters to the function Convert Celsius to Fahrenheit Convert Fahrenheit to Celsius Take a numeric score as a parameter and return the associated letter grade Note, the functions that perform calculations should NOT print anything. They should only return the calculated value back to main) to be printed. Deliverable: Please submit a SINGLE C file containing all of your functions. Also, please call each from main, so that all functions are run when the program runs

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include<stdio.h>

//function prototypes

void printName(char[]);

void printNumbers1to10();

void printNumbersNtoM(int,int);

int getBaseToExponent(int, int);

float convertCelsiusToFahrenheit(float);

float convertFahrenheitToCelsius(float);

char getLetterGrade(float);

int main()

{

                char name[150];

                int n, m;

                int b, e, result;

                float tempInC, tempInF;

                float score;

               

                //prompt and read a name

                printf("Enter your name: ");

                scanf("%s",name);

               

                //print name using printName function

                printName(name);

               

                //print numbers from 1 to 10

                printf("\nNumbers from 1 to 10: ");

                printNumbers1to10();

               

                //print number from N to M

                //prompt and read values for N and M

                printf("\n\nEnter two values for N and M to print numbers from N to M: ");

                scanf("%d %d", &n,&m);

                //print numbers using printNumbersNtoM by passing n and m as parameters

                if(n <= m)

                {

                                printf("\nNumbers from %d to %d: \n\n", n, m);

                                printNumbersNtoM(n, m);

                }                             

                //if n > m then display an error message

                else

                                printf("\nN must be less than M\n");

                               

                //prompt and read values for base and exponent

                printf("\n\nEnter two values for BASE and EXPONENT: ");

                scanf("%d %d", &b,&e);

                if(e > 0)

                {

                                result = getBaseToExponent(b, e);

                                printf("\nThe value of base %d to exponent %d is: %d\n", b, e, result);

                }

                //display an error message if exponent is negative

                else

                {

                                printf("\nThe value for exponent cannot be negative.");

                }

               

                //prompt and read temperature in Celsius

                printf("\nEnter temperature in Celsius: ");

                scanf("%f", &tempInC);

               

                //print the temperature in Fahrenheit

                printf("\nThe temperature in Fahrenheit is: %.2f", convertCelsiusToFahrenheit(tempInC));

               

                //prompt and read temperature in Fahrenheit

                printf("\n\nEnter temperature in Fahrenheit: ");

                scanf("%f", &tempInF);

               

                //print the temperature in Fahrenheit

                printf("\nThe temperature in Celsius is: %.2f", convertFahrenheitToCelsius(tempInF));

               

                //prompt and read score

                printf("\n\nEnter the number score: ");

                scanf("%f", &score);

                printf("\nThe letter grade for the score is: %c", getLetterGrade(score));

                return 0;

}

//method that takes your name as parameter and prints it

void printName(char name[])

{

                printf("\nName: %s\n",name);

}

//method that prints numbers from 1 to 10

void printNumbers1to10()

{

                int num = 1;

                //run a loop from 1 and 10 and print each number

                while(num <= 10)

                {

                                printf("%d ",num);

                                num++;

                }

}

//method that prints numbers from N to M

void printNumbersNtoM(int n, int m)

{

                //run a loop from n to m and print the numbers from n to m

                while(n <= m)

                {

                                printf("%d ",n);

                                n++;

                }

}

//method that calculates a base to a exponent

int getBaseToExponent(int b, int e)

{

                int result = 1;

                int i = 1;

                //run a loop from 1 to e

                while (i <= e)

                {

                                //muliply b to result

                                result = result * b;

                                i++;

                }

                //return the result

                return result;

}

//method that converts temperature in Celsius to Fahrenheit

float convertCelsiusToFahrenheit(float tempInC)

{

                //convert and return temperature in Fahrenheit

                float tempInF = (tempInC * 1.8) + 32;

                return tempInF;

}

//method that converts temperature in Fahrenheit to Celsius

float convertFahrenheitToCelsius(float tempInF)

{

                //convert and return temperature in Fahrenheit

                float tempInC = (tempInF - 32) / 1.8;

                return tempInC;

}

char getLetterGrade(float score)

{

                char letterGrade;

                //if score is 90 and above grade is A

                if(score >= 90)

                                letterGrade = 'A';

                //if score between 80 and 89 grade is B

                else if(score >= 80 && score <= 89)

                                letterGrade = 'B';

                //if score between 70 and 79 grade is C

                else if(score >= 70 && score <= 79)

                                letterGrade = 'C';

                //if score between 60 and 69 grade is D

                else if(score >= 60 && score <= 69)

                                letterGrade = 'D';

                //if score below 59 grade is F

                else if(score <= 59)

                                letterGrade = 'F';

                return letterGrade;

}

Output:

Let me know if you have any concerns

Add a comment
Know the answer?
Add Answer to:
Please write individual functions solving each of the following problems: Print your name Print numbers 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. In Python, Write a function to convert inches into yards, feet and inches. The functions...

    1. In Python, Write a function to convert inches into yards, feet and inches. The functions should take one parameter, 'inches', and print out the number of yards, feet, and inches equivalent to the value of the argument. Call the function after prompting the user to enter the number of inches. Don't forget to convert the input to an 'int'. 2. In Python,Write a function to convert celsius to fahrenheit. The function should return a value, which you should assign...

  • Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The...

    Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...

  • Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The...

    Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom function c_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a value-returning...

  • FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice...

    FOR PYTHON Write a Python program that can convert a Fahrenheit temperature to Celsius, or vice versa. The program should use two custom functions, f_to_c and c_to_f, to perform the conversions. Both of these functions should be defined in a custom module named temps. Custom functionc_to_f should be a void function defined to take a Celsius temperature as a parameter. It should calculate and print the equivalent Fahrenheit temperature accurate to three decimal places. Custom function f_to_c should be a...

  • Question 1: Write down an function named bitwisedFloatCompare(float number1, float number2) that tests whether a floating...

    Question 1: Write down an function named bitwisedFloatCompare(float number1, float number2) that tests whether a floating point number number1 is less than, equal to or greater than another floating point number number2, by simply comparing their floating point representations bitwise from left to right, stopping as soon as the first differing bit is encountered. The fact that this can be done easily is the main motivation for biased exponent notation. The function should return 1 if number1 > number2, return...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

  • Please place all of the following functions (defun …) into a SINGLE .lsp file As such,...

    Please place all of the following functions (defun …) into a SINGLE .lsp file As such, be sure to use the EXACT SAME function names and parameter numbers and orders I provide ​ Write a function ONEFIB that takes a single parameter n and returns the nth Fibonacci number. Write a function ALLFIB that takes a single parameter n and returns a list of the first n Fibonacci numbers. Do not worry about efficiency here. HINT: You can use ONEFIB...

  • Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The...

    Need help problem 9-13 C++ Homework please help WRITE FUNCTION PROTOTYPES for the following functions. The functions are described below on page 2. (Just write the prototypes) When necessary, use the variables declared below in maino. mm 1.) showMenu m2.) getChoice 3.) calcResult m.) showResult 5.) getInfo mm.) showName 7.) calcSquare 8.) ispositive int main { USE THESE VARIABLES, when needed, to write function prototypes (#1 - #8) double num1 = 1.5; double num2 = 2.5; char choice; double result;...

  • Please Use C++ for coding . . Note: The order that these functions are listed, do...

    Please Use C++ for coding . . Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all.cpp, input and output files for grading. Write a complete program that uses the functions listed below. Except for the printodd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention...

  • Write a complete program that uses the functions listed below. Except for the printOdd function, main...

    Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT