Thread: I'm Stuck!! - Creating Sentinel Program dealing with Grades

  1. #1
    Registered User
    Join Date
    Jul 2016
    Posts
    7

    I'm Stuck!! - Creating Sentinel Program dealing with Grades

    I'm completely new to programming, as I am taking COP 1000. I only know what's been taught. This is the assignment that's being asked of me:

    In this part you will write a C program to solve a problem described in English.

    Create a sentinel controlled while loop that will ask the user to enter student grades until a value of -1 is entered. Use a counter variable to count all the grades that are passing grades, where 70 is the minimum passing grade. If there are any grades that are out of the range 0 – 100, present an error message to the user, and do not count that grade as passing.

    Create 4 test cases. Use this as one of them:

    Grades Entered: Expected Results
    45
    90
    70
    87
    123 “That is not a valid grade!”
    100
    -1 You entered 4 passing grades.


    I can not for the life of me figure this out. Where I'm getting stuck is trying to get the program to calculate the total passing grades at the end.

    This is what I've got so far. It's very amateurish I'm sure. The reason why I was trying to convert the grade to "1" is because I was trying to make that accumulate to create a number of total passing grades. I've been on this for hours and I've realized that that method probably won't work. However, I don't know what to do. This is due tomorrow and I can't figure out how to do this.

    The code is below:

    Code:
    
    
    Code:
    #include <stdio.h>;
    #include <stdlib.h>
    
    
    main() {
    
    
        int grade, totalPassing = 1;
        printf("Enter test grade  (-1 to quit):");
        scanf_s("%i", &grade);
    
    
        while (grade != -1)
        {
            printf("Enter test grade  (-1 to quit):");
            scanf_s("%i", &grade);
    
    
            {
                if (grade > 100 || grade < 70)
                    printf("That is not a valid grade! \n");
            }
    
    
            if (grade <= 100 && grade >= 70)
                grade = 1;
            else
                grade = 0;
        }
            totalPassing = grade + 1;
    
    
        printf("You've entered %i passing grades! \n");
    
    
    
        system("pause");
    }

  2. #2
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Sir/Maam,

    This should work:
    Code:
    #include <stdio.h>;
    #include <stdlib.h>
    #include <conio.h>
    
    int main()
    
    {
    int grade, totalPassing;
    
    totalPassing = 0;
    grade = 0;
    
    while (grade != -1)
    {
    printf("Enter test grade  (-1 to quit):");
    scanf("%d", &grade);
    
    if(grade == -1)
    {
    grade = -1;
    }
    else if(grade <= 100 && grade >= 70)
    {
    totalPassing = totalPassing + 1;
    }
    else
    {
    grade = 0;
    }
    }
    
    printf("You've entered %d passing grades! \n", totalPassing);
    
    getch();
    }

  3. #3
    Registered User
    Join Date
    Jul 2016
    Posts
    7
    Thanks so much! It's definitely got me back in the game. I've adjusted the code to fit what we're studying and what we know. I also altered it so that it'll print "This is not a valid grade!" when an invalid grade is entered. I'm trying now, to figure out how I can avoid that statement when "-1" is entered. Since "-1" is used to end the loop, how do I set it up where that statement doesn't follow?

    Code:
    #include <stdio.h>;
    #include <stdlib.h>
    
    
    int main()
    
    
    {
    	int grade, totalPassing;
    
    
    	totalPassing = 0;
    	grade = 0;
    
    
    	while (grade != -1)
    	{
    		printf("Enter test grade  (-1 to quit):");
    		scanf_s("%d", &grade);
    
    
    		if (grade < 70 || grade > 100)
    			printf("This is not a valid grade! \n");
    		
    
    
    		if (grade == -1)
    		{
    			grade = -1;
    		}
    		else if (grade <= 100 && grade >= 70)
    		{
    			totalPassing = totalPassing + 1;
    		}
    		else
    		{
    			grade = 0;
    		}
    
    
    	}
    
    
    	printf("You've entered %d passing grades! \n", totalPassing);
    
    
    	system("pause");
    }

  4. #4
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Jesus Christ! Sir, if you put scanf instead of the similar statement it would work on my end. I'm sorry if I'm wrong. I'm trying the best I can to answer the question on my limited training. I consider myself rather new compared to the old timers who's been around for decades officially. I only have 2 years of community college and 2 years of home school independly. My first language is Vietnam. Thank you for your waiver.

  5. #5
    Registered User
    Join Date
    Jul 2016
    Posts
    7
    Quote Originally Posted by Tien Nguyen View Post
    Jesus Christ! Sir, if you put scanf instead of the similar statement it would work on my end. I'm sorry if I'm wrong. I'm trying the best I can to answer the question on my limited training. I consider myself rather new compared to the old timers who's been around for decades officially. I only have 2 years of community college and 2 years of home school independly. My first language is Vietnam. Thank you for your waiver.
    Yeah, scanf_s only works with what we're using(Visual Studio 2015). Thanks again for your help. It's done better for me than I did on my own!

  6. #6
    Registered User
    Join Date
    Jul 2016
    Posts
    7
    I've figured it out! Thanks again for everything. You're code was more right then I originally realized. I misread the directions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stuck on creating a program with array
    By DecoratorFawn82 in forum C++ Programming
    Replies: 16
    Last Post: 03-13-2013, 07:06 PM
  2. Grades calculating program help please!
    By hotshotennis in forum C Programming
    Replies: 93
    Last Post: 04-24-2012, 12:08 PM
  3. Simple Program for grades. Little help please.
    By kordric in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2008, 12:29 AM
  4. Please help! Stuck on card dealing program.
    By Randoon in forum C Programming
    Replies: 3
    Last Post: 11-22-2002, 08:05 PM
  5. Replies: 13
    Last Post: 08-15-2002, 09:20 AM

Tags for this Thread