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.
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 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++ 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 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...
write a program in c++ that asks the user to enter their 5 test scores and...
write a program in c++ that asks the user to enter their 5 test scores and calculates the most appropriate mean. Have the results print to a text file and expected results to print to screen.
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
In the space provided below write a C++ program that asks the user to enter their...
In the space provided below write a C++ program that asks the user to enter their quarterly earnings for the past two years stores the data in a 2-dimensional array. The program then computes both the annual earnings as well as the total earning and prints the results along with the 2-dimensional array on screen as well as onto a file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT