Question

In: Computer Science

Use a for loop to ask a user to enter the grades of 5 courses. The...

Use a for loop to ask a user to enter the grades of 5 courses. The user should enter character
values, e.g., A. Calculate the GPA of the user
Hint: Convert the character values entered to numerals, e.g., A to 4
c programming
help me please

Solutions

Expert Solution

My Assumption here is

A -> 4

B -> 3

C -> 2

D -> 1

E -> 0

Here is the code

=============================================================

#include <stdio.h>

#include <stdlib.h>

int main(){

  char grades[5];

  int nums[5];

  char temp;        // To clear the buffer

  printf("\nEnter grades of 5 subjects:\n\n");

  for(int i = 0;i < 5; i++)

  {

    printf("Enter Grade of subject %d:", (i+1));

    scanf("%c%c", &grades[i], &temp);

    if(grades[i] == 'A'){

      nums[i] = 4;

    }

    else if(grades[i] == 'B'){

      nums[i] = 3;

    }

    else if(grades[i] == 'C'){

      nums[i] = 2;

    }

    else if(grades[i] == 'D'){

      nums[i] = 1;

    }

    else if(grades[i] == 'E'){

      nums[i] = 0;

    }

    else{

      printf("\nInvalid Marks\n Please try again");    

      i--;    // So as to ask input for the same number again

    }

  }

  for(int i = 0; i < 5; i++){

    printf("\nNumber for subject %d is %d", (i+1), nums[i]);

  }

  return 0;

  

}

=============================================================


Related Solutions

Write in C# please! Ask the user to enter all of their exam grades. Once they...
Write in C# please! Ask the user to enter all of their exam grades. Once they are done, calculate the minimum score, the maximum score and the average score for all of their scores. Perform this using at least 2 Loops (can be the same type of loop) and not any built in functions.
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The program will use a while loop to let the program keep running. The user will be allowed to use the program as long as the quitVariable is equal to 'y' or 'Y'. When the user decides to quit playing, say "Thanks for playing!". The program will use a for loop to test if the number are even or odd. If even print "number is...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the...
PYTHON Ask the user to enter the number of students in the class. Thereafter ask the user to enter the student names and scores as shown. Output the name and score of the student with the 2nd lowest score. NOTE: You may assume all students have distinct scores between 0 and 100 inclusive and there are at least 2 students NOTE: You may only use what has been taught in class so far for this assignment. You are not allowed...
In MatLab 1. Ask the user to enter a 1 x 5 vector of numbers. Determine...
In MatLab 1. Ask the user to enter a 1 x 5 vector of numbers. Determine the size of the user entry. 2. Ask the user to enter a 1 x 5 vector of numbers. Determine the size of the user entry. If the user enters a 5 x 1 vector, use a warning statement to inform the user of their error, and set the new input value to be the transpose of the user input value. If the user...
Use a sentinel while loop that repeatedly prompts the user to enter a number, once -1...
Use a sentinel while loop that repeatedly prompts the user to enter a number, once -1 is entered, stop prompting for numbers and display the maximum number entered by the user. I am struggling to have my program print the math function. Here is what I have so far: import java.util.*; public class MaxSentinel { public static void main(String[] args) {    Scanner input = new Scanner(System.in); System.out.println("Please enter a value. Press -1 to stop prompt."); int number = 0;...
Write a java program that will ask the user to enter integers (use loops) until -100...
Write a java program that will ask the user to enter integers (use loops) until -100 is entered. The program will find and display the greatest, the smallest, the sum and the average of the entered numbers. also write a separate driver class which will be used to run and display the greatest, the smallest, the sum and the average of the entered numbers. Thanks!!
Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
put a loop around the main module that will ask the user if they want to...
put a loop around the main module that will ask the user if they want to run the program again with another week of lemonade and cookie sales. def main():    # constants given CUP_COST= .05 LEMONADE_MIX_OZ_COST =.10 COSTOFCOOKIES = .11 COOKIESALE = .25 #inputs numberOfCupsUsed=int(input('Enter the number of cups used this week ')) ouncesOfMixUsed=int(input('Enter ounces of Lemonade mix used ')) salesForWeekLemonade=float(input('Enter total Lemonade sales for the week $')) cookiesSoldForWeek = int(input("Enter number of cookies sold for the week: "))...
I need to ask a user what numbers they want to enter. They can enter as...
I need to ask a user what numbers they want to enter. They can enter as many as they like. Then inside I need to use conditionals to determine if the numbers are <=20, <=323 && > 30, >200. I can't figure out how to let the user enter as many inputs as they want. I know I need to use a loop to check each number entered and determine if it is small middle or greater but I can't...
In C# When the user enters an invalid value, ask the user to repeatedly enter the...
In C# When the user enters an invalid value, ask the user to repeatedly enter the value until a valid value has been entered. Gender must be ‘M’ or ‘F’. Residency must be ‘I’ or ‘O’. Existing Code: using System; public class Student {   public int credit;   public String firstname, lastname, gender, residency, edate;   public void input()   {     Console.WriteLine("\nWelcome to the Continental University Registration System!"); Console.WriteLine("\nEnter data about a student"); Console.Write("First Name: "); firstname = Console.ReadLine(); Console.Write("Last Name: "); lastname...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT