Question

Question- How would I allow the program to run both upper and lower case letters. How...

Question- How would I allow the program to run both upper and lower case letters. How would I write a switch statement for upper and lower cases to see if the value entered for Grade2 is a A or a?

C programming

int main()
{
char Grade2;
float gradepoint;
char Grade = 'X'; // Declares a character type variable named Grade

printf("Enter a grade\t"); // Prompts for Grade
scanf("%c", &Grade); // Inputs Grade

printf("Grade is: \t%c\n", Grade); // Prints the value of Grade
// Part 3 - using if else statements
if(Grade=='A')
{
printf("The Value of an A is 4.0");
}
else if(Grade=='B')
{
printf("The Value of a B is 3.0");
}
else if(Grade=='C')
{
printf("The Value of C is 2.0");
}
else if(Grade=='D')
{
printf("The Value of D is 1.0");
}
else if(Grade=='D')
{
printf("The Value of F is 0.0");
}
else if(Grade=='F')
{
printf("The value of <entered value of Grade> is not defined");
}
// Part 4- using switch-case-break statements
fflush(stdin); //This clears the scanf buffer

printf("\nEnter Grade2\t");
scanf("%c", &Grade2);

printf("Grade2 is: \t%c\n", Grade2);

Make Grade2= 'A' //changes entry to upper case only
Make gradepoint= 4.0f // sets grade-point to 4.0 if grade is 'A'
Print"Grade2:<tab><value of grade2>has value of<gradepoint formatted as 3.1>
getch();
return 0;
}

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

Below is the code for the above problem:

#include<stdio.h>
#include<stdlib.h>
int main()
{
char Grade2;
float gradepoint;
char Grade = 'X'; // Declares a character type variable named Grade

printf("Enter a grade\t"); // Prompts for Grade
scanf("%c", &Grade); // Inputs Grade

printf("Grade is: \t%c\n", Grade); // Prints the value of Grade
// Part 3 - using if else statements
if(Grade =='A' || Grade == 'a')
{
printf("The Value of %c is 4.0",Grade);
}
else if(Grade=='B' || Grade == 'b')
{
printf("The Value of %c is 3.0",Grade);
}
else if(Grade=='C' || Grade == 'c')
{
printf("The Value of %c is 2.0",Grade);
}
else if(Grade=='D' || Grade == 'd')
{
printf("The Value of %c is 1.0",Grade);
}
else if(Grade=='F' || Grade == 'f')
{
printf("The Value of %c is 0.0",Grade);
}
else
{
printf("The value of %c is not defined",Grade);
}
// Part 4- using switch-case-break statements
fflush(stdin); //This clears the scanf buffer
getchar();
printf("\nEnter Grade2\t");
scanf("%c", &Grade2);

printf("Grade2 is: \t%c\n", Grade2);
switch(Grade2)
{
case 'A':
case 'a': gradepoint = 4.0;
break;
case 'B':
case 'b': gradepoint = 3.0;
break;
case 'C':
case 'c': gradepoint = 2.0;
break;
case 'D':
case 'd': gradepoint = 1.0;
break;
case 'F':
case 'f': gradepoint = 0.0;
break;
default:
printf("The value of %c is not defined",Grade);
return 0;
}
printf("Grade2:\t%c has value of %0.1f\n",Grade2,gradepoint);
return 0;
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Question- How would I allow the program to run both upper and lower case letters. How...
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
  • C++ HELP I need help with this program. I have done and compiled this program in...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...

  • C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. But I need to split this program in three files 1. bill.h = contains the class program with methods and variables 2. bill.cpp = contains the functions from class file 3. main.cpp = contains the main program. Please split this program into three files and make the program run. I have posted the code here. #include<iostream>...

  • I am trying to run this program in Visual Studio 2017. I keep getting this build...

    I am trying to run this program in Visual Studio 2017. I keep getting this build error: error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". 1>Done building project "ConsoleApplication2.vcxproj" -- FAILED. #include <iostream> #include<cstdlib> #include<fstream> #include<string> using namespace std; void showChoices() { cout << "\nMAIN MENU" << endl; cout << "1: Addition...

  • The following code is a C Program that is written for encrypting and decrypting a string....

    The following code is a C Program that is written for encrypting and decrypting a string. provide a full explanation of the working flow of the program. #include <stdio.h> int main() { int i, x; char str[100]; printf("\n Please enter a valid string: \t"); gets (str); printf ("\n Please choose one of the following options: \n"); printf ("1 = Encrypt the given string. \n"); printf("2 = Decrypt the entered string. \n"); scanf("%d",&x); // using switch case statements switch (x) {...

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

  • Hello! I'm posting this program that is partially completed if someone can help me out, I...

    Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...

  • Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU...

    Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • // CSE240 Spring 2019 HW 7 & 8 // Write your name here // Write the...

    // CSE240 Spring 2019 HW 7 & 8 // Write your name here // Write the compiler used: Visual studio or gcc // READ BEFORE YOU START: // You are given a partially completed program that creates a linked list of patient information. // The global linked list 'list' is a list of patients with each node being struct 'patientList'. // 'patientList' consists of struct 'patient' which has: patient name, room number, and a linked list of 'doctors'. // The...

  • // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given...

    // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given a partially completed program that creates a list of patients, like patients' record. // Each record has this information: patient's name, doctor's name, critical level of patient, room number. // The struct 'patientRecord' holds information of one patient. Critical level is enum type. // An array of structs called 'list' is made to hold the list of patients. // To begin, you should trace...

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