Question

Code goes like: #include <stdio.h> /* * askGrade(): * Asks the student for a letter grade...

Code goes like:

#include <stdio.h>

/*
* askGrade():
* Asks the student for a letter grade
* (A = 90-100, B = 80-89, etc.)
* then gives the appropriate letter grade in upper case.
*/
void askGrade() {
int grade;
  
printf("Enter your grade:");
scanf("%d", &grade);
  
printf("Your grade is: ");
  
// BEGIN YOUR CODE
  
// TODO: Use if-else statements to print the right letter grade.
  
// END YOUR CODE
  
printf("\n");
}

/*
* dayOfTheWeek():
* Asks the student for a number, representing the day
* of the week (Monday = 1, Tuesday = 2, etc.),
* Then prints the name of the day.
*/
void dayOfTheWeek() {
int day;
  
printf("Enter the number of the day of the week:");
scanf("%d", &day);
  
printf("Today is ");
  
// BEGIN YOUR CODE
  
// TODO: Use switch statements to print the right letter grade.
  
// END YOUR CODE
  
printf("\n");
  
}


int main(void) {
// Call the first method
askGrade();
dayOfTheWeek();
return 0;
}

---------------------------------------------------------------------------

The objective of this exercise is to practice using conditionals

There are two sections of code you have to write, they are enclosed like this:

\\ BEGIN YOUR CODE

\\ TODO: Description of the task

\\ END YOUR CODE

The first section is in the askGrade() method. You have to use If-Else statements to check the range of a grade and assign it a letter grade:

  • A = 90-100

  • B = 80-89

  • C = 70-79

  • D = 60-69

  • F = 0-59

  • ERROR, otherwise

You only have to print out the right letter using printf().

----------------------------------------------------

The second section is in the dayOfTheWeek() method. You have to use a Switch statement to print out the right day of the week:

  • Monday = 1

  • Tuesday = 2

  • Wednesday = 3

  • Thursday = 4

  • Friday = 5

  • Saturday = 6

  • Sunday = 7

  • ERROR, for all other numbers

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

#include<stdio.h>
#include<conio.h>
void askGrade()
{
int n;
printf("enter the grade: ");
scanf("%d",&n);
printf("\n");
   if(n<=100 && n>=90)
   {
   printf("A");
   }
   else if(n<=89 && n>=80)
   {
   printf("B");
   }
   else if(n<=79 && n>=70)
   {
   printf("C");
   }
   else if(n<=69 && n>=60)
   {
   printf("D");
   }
   else if(n<=59 && n>=0)
   {
   printf("F");
   }
   else
   {
   printf("Error");
   }
printf("\n");
}
void dayOfTheWeek()
{
int d;
printf("enter the number: ");
scanf("%d",&d);
printf("\n");
switch(d)
{
   case 1:
   {
   printf("Today is Monday");
   break;
   }
   case 2:
   {
   printf("Today is Tuesday");
   break;
   }
   case 3:
   {
   printf("Today is Wednesday");
   break;
   }
   case 4:
   {
   printf("Today is Thursday");
   break;
   }
   case 5:
   {
   printf("Today is Friday");
   break;
   }
   case 6:
   {
   printf("Today is Saturday");
   break;
   }
   case 7:
   {
   printf("Today is Sunday");
   break;
   }
   default:
   printf("Error");


}
}
main()
{
clrscr();
askGrade();
dayOfTheWeek();

getch();
}

DON'T FORGET TO LIKE.

THANKS BY HEART.

Add a comment
Know the answer?
Add Answer to:
Code goes like: #include <stdio.h> /* * askGrade(): * Asks the student for a letter grade...
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
  • MATLAB Code: ?MATLAB Code: Write a function that converts a given letter grade it will print...

    MATLAB Code: ?MATLAB Code: Write a function that converts a given letter grade it will print its equivalence in numerical scale. For example if the user enters A, then your function should print a message stating that the grade must be between 90 and 100. B is between 80 and 89, etc. Everything under 60 is F. Use the switch-case function. Use fprintf to display the results on the screen.

  • Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int...

    Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...

  • C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure...

    C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure you test your code. Supplied code #include <stdio.h> int main(void) { char ch; int countA = 0; int countE = 0; int countI = 0; printf("Enter in a letter A, E, or I.\n"); scanf(" %c", &ch); //Replace the following block with your switch if(ch == 'E' || ch == 'e') countE++; else if(ch == 'A' || ch == 'a') countA++; else if(ch == 'I'...

  • #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here....

    #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } }    return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...

  • #include <stdio.h> #include string.h     #define C17_PRICE 12.80 #define F25_PRICE 4.29 #define DN3_PRICE 10.00 #define GG7_PRICE...

    #include <stdio.h> #include string.h     #define C17_PRICE 12.80 #define F25_PRICE 4.29 #define DN3_PRICE 10.00 #define GG7_PRICE 35.00 #define MV4_PRICE 18.49 #define DISCOUNT        0.05 #define DISC_THRES    10 #define SAME_DAY_DELIVERY =   35.0 #define NEXT_DAY_DELIVERY =   20.0    typedef enum{ WRONG, C17, F25, DN3, GG7, MV4} part     /*--- Function Prototypes ------------*/ part getPartType ( void ); int getquantity ( void ); int getDeliveryOption ( void ); float calcPriceOfParts( part orderedPart, int quantity ); float calcTotalCarges ( float orderPrice, char...

  • Below is a java program that inputs an integer grade and turns it into a letter...

    Below is a java program that inputs an integer grade and turns it into a letter grade. Update the below java code as follows and comment each line to explain what is happening: 1. Convert the if-else-if code block to a switch statement to solve the problem. 2. Use modulus to convert the grade input so that the range of grades are converted to one value. (comment the line) import java.util.Scanner; public class GradeLetterTest { public static void main(String[] args)...

  • Digit to WordsWrite a C program that asks the user for a two-digit number, then prints...

    Digit to WordsWrite a C program that asks the user for a two-digit number, then prints the English wordfor the number. Your program should loop until the user wants to quit.Example:Enter a two-digit number: 45You entered the number forty-five.Hint: Break the number into two digits. Use one switch statement to print the word for the firstdigit (“twenty,” “thirty,” and so forth). Use a second switch statement to print the word for thesecond digit. Don’t forget that the numbers between 11...

  • Hello, I need help with the following C code. This program asks the user to enter...

    Hello, I need help with the following C code. This program asks the user to enter three numbers and outputs the sum on the screen , all im trying to do is have the program reprompt the user for a number if anything other than a number is entered for each of the entries. I wanted to use do while for each of the functions but that did not work for example: Enter Number 1: 2 Enter Number 2: Hello...

  • 1. Create a program that takes a numerical score and outputs a letter grade. 2. In...

    1. Create a program that takes a numerical score and outputs a letter grade. 2. In this program, create two void functions titled makeScore and theGrade with an int argument. 3. The function makeScore should have a Reference parameter and theGrade should have a Value parameter. Note: Specific numerical scores and letter grades are listed below: 90-100 = Grade A 80-89 = Grade B 70-79 = Grade C 60-69 = Grade D 0-59 = Grade F 4. The function makeScore...

  • Write a C++ program that will provide a user with a grade range if they enter...

    Write a C++ program that will provide a user with a grade range if they enter a letter grade. Your program should contain one function. Your function will accept one argument of type char and will not return anything (the return type will be void), but rather print statements to the console. Your main function will contain code to prompt the user to enter a letter grade. It will pass the letter grade entered by the user to your function....

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