Question

In: Computer Science

write a C program that the user will enter how many subjects he has then the...

write a C program that the user will enter how many subjects he has then the user will Enter grades for each subject he has after that the user will enter a grade for the subject out of 100 and the GBA will be counted for him the GBA will be out of 5 and If his GBA is 4.5 and above, print congratulations you got bonus + the GBA will Multiply to 20 and if it's above 80, print Congratulations, you have been accepted into the College of Computer Science and Engineering

Solutions

Expert Solution

The C program to take number of subjects(n) as input and to read scores of n subjects to calculate GBA and to print results accordingly is:

#include<stdio.h>

// input_scores() function takes score of a subject from user
// and checks if the score is vvalid. If then then score is returned
int input_scores(int i){
    int sc;
     printf("Subject %d score: ",i);
     scanf("%d",&sc);
     //Checking if score is less than 0 and greater than 100
     //If yes then this function is called again to read input again
     //It repeats till user enter valid input
     if(sc<0 || sc>100){
         printf("Invalid score!! Score can't be less than 0 and greater than 100\nTry again!\n");
         input_scores(i);
     }
     else
     {
         return sc;
     }
     
}

//Program execution starts here
int main(void){
    //Declaring a variable numofsubs
    int numofsubs;
    printf("Enter number of subjects : ");
    //Taking number of subjects as input from user
    //and storing in numofsubs variable
    scanf("%d",&numofsubs);
    //Creating a integer array scores[] of size numofsubs
    int scores[numofsubs];
    //Declaring a floaating point varibale avg to store average of scores
    float avg=0;
    printf("Enter scores of each subject \n");
    //Calling input_scores() function numofsubs times
    //to take numofsubs scores from user
    for(int i=0;i<numofsubs;i++){
        scores[i]=input_scores(i+1);
        //adding the read score to avg variable to calculate average at the end
        avg = avg +scores[i];
    }
    //Calculating average
    avg = avg/numofsubs;
    //GBA is given by multiplying avg by 5 and dividing by 100
    //This gives GBA out of 5
    float gba = (5*avg)/100;
    printf("Your GBA is: %f\n",gba);

    //Checking for given conditions and printing respective outputs
    if(gba>=4.5)
    printf("Congratulations!!! You got bonus\n");
    if(gba*20>80)
    printf("Congratulations, you have been accepted into the College of Computer Science and Engineering");
    else
    {
        printf("Sorry your GBA is low!!");
    }
    
}

Code Snippet:

I have calculated GBA by first calculating the average of grades, then multiplying the average by 5 and dividing with 100 gives GBA out of 5.

Now I checked if GBA is greater than 4.5. If yes then Bonus is printed.

Then checked if GBA times 20 is greater than 80. If yes, then printed the message "Congratulations, you have been accepted into the College of Computer Science and Engineering".

I have provided comments in the program explaining lines of code. I have tested the code for all possible cases and it is doing good. This code also handles exceptions like scores less than 0 and greater than 100.

I am sharing few output screenshots for your reference.

Hope this answer helps you.

Thank you :)


Related Solutions

How to write a C++ program that lets the user enter a string and checks if...
How to write a C++ program that lets the user enter a string and checks if it is an accepted polynomial. Accepted polynomials need to have one term per degree, no parentheses, spaces ignored.
Write a program in Java to: Ask the user how many scores they want to enter...
Write a program in Java to: Ask the user how many scores they want to enter (=> Create an array based the entered size) Ask the user to enter their scores in the quarter (Fill the array with the entered scores(assigned to elements)) ==>> Use a "for" loop Find the greatest score Calculate and show the average Show the final grade based on the average (For example A,B,C ... ) Print the scores (the elements of the array) => Use...
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...
Write a C program Your program will prompt the user to enter a value for the...
Write a C program Your program will prompt the user to enter a value for the amount of expenses on the credit card. Retrieve the user input using fgets()/sscanf() and save the input value in a variable. The value should be read as type double. The user may or may not enter cents as part of the input. In other words, expect the user to enter values such as 500, 500.00 and 500.10. The program will then prompt the user...
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
Write a C++ program that : 1. Allow the user to enter the size of the...
Write a C++ program that : 1. Allow the user to enter the size of the matrix such as N. N must be an integer that is >= 2 and < 11. 2. Create an vector of size N x N. 3. Call a function to do the following : Populate the vector with N2 distinct random numbers. Display the created array. 4. Call a function to determines whether the numbers in n x n vector satisfy the perfect matrix...
Write a program using C++ that ask the user for the flowing: How many shares to...
Write a program using C++ that ask the user for the flowing: How many shares to be bought: The price per share: Percent commission for the broker for each transaction: Average annual return as of percentage: The program should calculate and display the following: The amount paid for the stock alone (without the commission) The amount of the commissionThe total amount of paid (the payment for stock plus the commission) After TEN years, your shares will worth:
Write a C++ program that asks the user to enter the monthly costs for the following...
Write a C++ program that asks the user to enter the monthly costs for the following expenses incurred from operating your automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and a projected total annual cost of these expenses. Label each cost. The labels should be left aligned and have a column width of 30 characters. The cost should be aligned right and displayed with two decimal places...
Write a C program that loops and asks a user to enter a an alphanumeric phone...
Write a C program that loops and asks a user to enter a an alphanumeric phone number and converts it to a numeric one. No +1 at the beginning. You can put all code in one quiz1.c file or put all functions except main in phone.c and phone.h and include it in quiz1.c Submit your *.c and .h files or zipped project */ #pragma warning (disable: 4996) //windows #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h> enum { MaxLine =...
C++ write a program that asks the user to enter the hours and rate then calculate...
C++ write a program that asks the user to enter the hours and rate then calculate the gross pay for an employee, the program should test if the hours are regular (40), any hour more than 40 should be paid with the overtime rate: 1.5*rate. The program should ask repeatedly the user if he/she wants to continue: y or n, if the user types y, then the program should ask for the hours and rate for another employee then display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT