Click here to Skip to main content
16,015,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The purpose of this programme is to prompt the user for
category weights (of his/her grade) and then asks the user to
input his/her grades for each category
. It will then it find the
grade average of each category and use them to calculate the
user's final grade average and letter grade.

What I have tried:

include<stdio.h>
int main(){
printf("Welcome to the grade Calculator!\n");
printf("This program will input your homework,quizzes,tests,and final exams and calculate your average.\n");
char input;
int i,n,g;
bool t=true;
int sum=0,sum1=0,sum2=0,sum3=0;
int average;
//Input h for homework,q for quizzes,t for tests and f for final exams.
while(t==true){
scanf("%c",&input); 
if(input=="h"){
   printf("How many homework grades are to be entered?:");
   scanf("%d",n);
   for(i=1;i<=n;i++){
    printf("Grade%d:",&g);
    scanf("%d",&g);
    sum+=g;

   }
}
if(input=="q"){
   printf("How many quizzes grades are to be entered?:");
   scanf("%d",n);
   for(i=1;i<=n;i++){
    printf("Grade%d:",&i);
    scanf("%d",&gradei);
    sum1+=gradei; 
   }
}
if(input=="t"){
   printf("How many test grades are to be entered?:");
   scanf("%d",n);
   for(i=1;i<=n;i++){
    printf("Grade%d:",&i);
    scanf("%d",&gradei);
    sum2+=gradei
   }
}
if(input=="f"){
   printf("How many final grades are to be entered?:");
   scanf("%d",n);
   for(i=1;i<=n;i++){
    printf("Grade%d:",&i);
    scanf("%d",&gradei);
    sum3+=gradei;
   }
}
printf("Do you want to input any other grade:");
scanf("%c",input);
else{
t=false;
}
}

}
Posted
Updated 25-Mar-22 8:13am
v3

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Just saying "I tried" and expecting others to do it for you isn't going to cut it.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
Saloni Choudhary 25-Mar-22 11:51am    
I understand that and I do know coding but I am not able to even start. I am still trying but not able to understand how to proceed.
Saloni Choudhary 25-Mar-22 11:56am    
I have posted what I tried doing but I am very confused.
OriginalGriff 25-Mar-22 12:06pm    
First, indent that properly so it's readable, and replace all the single character variables with descriptive names: cntHomework, cntQuiz, ... so that you are maintaining separate counts. And maintain separate sums as well!

Then the averages are easy to work out: sum / count == average

But tidy that mess up first - and then follow the link I gave you and read the article!
Saloni Choudhary 25-Mar-22 12:08pm    
ok
CPallini 25-Mar-22 13:19pm    
5.
As a beginner, it can be difficult to see where braces line up and where they are mismatch.

Do NOT do this:
int main(){
    if(){
    }
    else{
    }
}

Do this instead:
int main()
{
    if()
    {
    }
    else
    {
    }
}

It'll make it far easier to see where you messed up your braces. You have at least one extra brace where it doesn't belong.
 
Share this answer
 
Comments
CPallini 25-Mar-22 13:19pm    
5.
I made it 'compiling'
C
#include <stdio.h>
#include <stdbool.h>
int main()
{
  printf("Welcome to the grade Calculator!\n");
  printf("This program will input your homework,quizzes,tests,and final exams and calculate your average.\n");
  char input;
  int i,n,g;
  bool t=true;
  int sum=0,sum1=0,sum2=0,sum3=0;
  int average;
  //Input h for homework,q for quizzes,t for tests and f for final exams.
  while (t==true)
  {
    scanf("%c",&input);
    if(input=='h')
    {
      printf("How many homework grades are to be entered?:");
      scanf("%d",&n);
      for(i=1; i<=n; i++)
      {
        printf("Grade %d: ", g);
        scanf("%d",&g);
        sum+=g;
      }
    }
    if(input=='q')
    {
      printf("How many quizzes grades are to be entered?:");
      scanf("%d",&n);
      for(i=1; i<=n; i++)
      {
        printf("Grade %d:", i);
        scanf("%d",&g);
        sum1+=g;
      }
    }
    if(input=='t')
    {
      printf("How many test grades are to be entered?:");
      scanf("%d",&n);
      for(i=1; i<=n; i++)
      {
        printf("Grade %d:", i);
        scanf("%d",&g);
        sum2+=g;
      }
    }
    if(input=='f')
    {
      printf("How many final grades are to be entered?:");
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
        printf("Grade %d:",i);
        scanf("%d", &g);
        sum3+=g;
      }
    }
    else
    {
      t = false;
    }
    if ( t )
    {
      char c;
      printf("Do you want to input any other grade:");
      while ((c = getchar()) !='\n' && c != EOF) {}
    }
  }


Then, I made it better (use data structures and functions, Luke!)
C
#include <stdio.h>
#include <stdbool.h>

struct Grade
{
  char kind;
  const char * desc;
  bool valid;
  double average;
};


double input_grade(const char * desc);

int main()
{
  struct Grade grade[] =
  {
    { 'h', "homework", false, 0.0 },
    { 'q', "quizzes",  false, 0.0 },
    { 't', "tests",  false, 0.0 },
    { 'f', "final exams", false, 0.0 },
  };
  const int GRADES = sizeof(grade)/sizeof(grade[0]);

  printf("Welcome to the grade Calculator!\n");
  printf("This program will input your homework,quizzes,tests,and final exams and calculate your average.\n");

  while (true)
  {
    char input;
    printf("please choose a grade: ");
    input = getchar();
    int g;
    for (g=0; g < GRADES; ++g)
    {
      if ( input == grade[g].kind)
        break;
    }
    if ( g == GRADES)
      break;

    grade[g].average = input_grade(grade[g].desc);
    grade[g].valid = true;
    while ((input = getchar()) != '\n' && input != EOF) {}
  }

  for (int g=0; g < GRADES; ++g)
  {
    if (grade[g].valid )
      printf("your %s average is %g\n", grade[g].desc, grade[g].average);
  }

  return 0;
}

double input_grade(const char * desc)
{
  int items;
  double average = 0.0;
  printf("how many %s grades ? ", desc);
  scanf("%d", &items);
  for (int i = 0; i < items; ++i)
  {
    printf("grade %d: ", i);
    int g;
    scanf("%d", &g);
    average += g;
  }
  if ( items )
    average /= items;
  return average;
 
Share this answer
 
Comments
Patrice T 25-Mar-22 20:06pm    
+5
CPallini 26-Mar-22 3:38am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900