184k views
4 votes
Hello, I am actually a beginner in C language, so I need some help about it. I am making a program in which I take 3 subjects and take input of that from User. After that, I find the percentage of each subject depending on the marks I enter and then I try to find the Total percentage of 3 subjects (Main Goal). What is wrong with the code, and how can I fix it?

a) [Answer the coding issue]
b) [Provide a solution to the problem]
c) [Explain the problem in the code]
d) [Suggest a better programming language]

User Abelenky
by
8.1k points

1 Answer

6 votes

Final answer:

The problem with the code is that it does not calculate the percentages correctly for each subject and does not correctly calculate the total percentage. To fix this, you can take input from the user for the marks of each subject, calculate the percentage of each subject, add the percentages of all three subjects, and calculate the total percentage.

Step-by-step explanation:

The problem with the code is that it does not calculate the percentages correctly for each subject and does not correctly calculate the total percentage. To fix this, you can use the following steps:

  1. Take input from the user for the marks of each subject.
  2. Calculate the percentage of each subject by dividing the marks by the maximum marks for that subject and multiplying by 100.
  3. Add the percentages of all three subjects.
  4. Calculate the total percentage by dividing the sum of the percentages by 3.

For example, if the marks for subject 1 are 80 out of 100, subject 2 are 70 out of 100, and subject 3 are 90 out of 100, the percentage for each subject would be 80%, 70%, and 90% respectively. The total percentage would be (80+70+90)/3 = 80%.

User Hamza Siddiqui
by
8.2k points