Thread: C homework help

  1. #1
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693

    C homework help

    Need help finding out how to create a program that allows professor to enter grades and the program has to calculate the grades and order them into As Bs Cs ect 100-89.5 =A 89.4-79.5=B so on and so on it should look something like this at the end for example

    Enter next score (negative to stop) -- 89.5
    Score = 89.50 Grade = A
    Enter next score (negative to stop) -- 89.49
    Score = 89.49 Grade = B
    Enter next score (negative to stop) -- 90
    Score = 90.00 Grade = A
    Enter next score (negative to stop) -- 105
    Sorry, scores cannot exceed 100. Please re-enter -- 58
    Score = 58.00 Grade = F
    Enter next score (negative to stop) -- 70
    Score = 70.00 Grade = C
    Enter next score (negative to stop) -- 65
    Score = 65.00 Grade = D
    Enter next score (negative to stop) -- -1

    -------------------------
    Number of scores 6
    Number of A's 2
    Number of B's 1
    Number of C's 1
    Number of D's 1
    Number of F's 1
    High score 90.00
    Low score 58.00
    Average score 77.00
    Exam GPA 2.33
    -------------------------

    and the program has to be able to distinguish as many scores as the professor enters regardless, so i assume i need a loop of some sort

    so far i have
    {
    int num;
    printf("enter next score (negative to stop)\n");
    scanf("%i",&num);
    printf("score is %i \n", num);


    return 0;
    }

    I dont know how to incorporate a loop and how to assign the letter grade along with it.
    Yes i am a noob

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    I would suggest that you study this link Control structures along with Arrays, plus I would think that your course textbook would also be a place to review.


    Jim

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    So you've gpot your code as follow

    Code:
    {
    int num;
    printf("enter next score (negative to stop)\n");
    scanf("%i",&num);
    printf("score is %i \n", num);
    
    
    return 0;
    }
    You know the above code will read a value of the user and relay it back to the stdout. Try do this for n number of times. Thats is n being the max number of student for which you need to read the grades. This would be your first assignment. Like

    Code:
    {
    int num;
    
    while ( .... ) {
    printf("enter next score (negative to stop)\n");
    scanf("%i",&num);
    printf("score is %i \n", num);
    }
    
    return 0;
    }
    while syntac is as follow

    Code:
    while( condition )  while ( n < 10 ) { ... }
    {
         statment 1;
         statment 2;
         .
    }
    Read about loops in C.

    Other other hand, you need to make an effort to solve the problem. Or your no where near to getting help on this forum. We would appreciate people working hard to what they desire and will help if your stuck, but not asking us to write the code for you.

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  4. #4
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    After a user inputs the score how do i make the printf(enter next score); pop up again ive tried it in loops but it never stops and i need to know how to set it to where when the user inputs a negative number the program stops and it relays the information and data on test scores, like i have in the example above

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    144
    you can also use if else if statements and logical operators!

    check the below link. Similar to what you want
    Code:
    http://cboard.cprogramming.com/c-programming/134066-please-help-me-question.html

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by camel-man View Post
    After a user inputs the score how do i make the printf(enter next score); pop up again ive tried it in loops but it never stops and i need to know how to set it to where when the user inputs a negative number the program stops and it relays the information and data on test scores, like i have in the example above
    By including it in a loop.... that's what everyone is telling you, a couple have even given rough examples...

    Look in your C texts and documentation, see how loops work... then give it a try...

  7. #7
    Registered User
    Join Date
    Jan 2011
    Posts
    144
    here is something quick to get u thinking. Try do while and if else if statements

    so i said DO i.e. execute the statement enter score at least once. When the user enters the score, it looks at the if statements and displays the respective message AND THE STATEMENT "enter score" is repeated. If user inputs a negative score the program exits

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main()
    {
    	int score;
    	//assigning a character to each variable
    	char grade1= 'A';
    	char grade2='B';
    	
    
    	do
    	{
    	printf("Enter score: ");
    	scanf_s("%d",&score);
    
    	//compare imput with logical operator. If score is greater than 50 then display below msg
    	if (score>50 && score<80)
    	{
    	printf("Your grade is %c", grade1);
    	
    	}
    	
    	else if (score>80 && score<100)
    	{
    printf("Your grade is %c", grade2);
    	}
    	}while(score>0);
    
    	getchar();
    	return(0);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help about homework
    By agathery in forum C Programming
    Replies: 27
    Last Post: 05-19-2010, 09:17 PM
  2. Homework
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-03-2001, 04:39 PM
  3. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 04:49 PM
  4. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 03:16 PM
  5. Homework
    By kermi3 in forum Windows Programming
    Replies: 5
    Last Post: 09-15-2001, 11:48 AM