dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Calculating Grades program (Passing grades) (Failing Grades) in C++

  1. #1
    Join Date
    Oct 2018
    Posts
    1

    Calculating Grades program (Passing grades) (Failing Grades) in C++

    Hello everyone. I really need help with this assignment. It's for an online class and I didn't understand the lessons at all. I have been trying to figure out the code for 6 hours but I just don't understand how to solve this problem. Any help will be greatly appreciated by me and my fellow classmates.

    This is the assignment. So far we have only learned about repetition using a while loop and logical operators. So please keep that in mind.

    We want to count how many passing grades are entered. We don’t know how many grades there will be. Use 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 (meaning either less than zero or greater than 100), present an error message to the user, and do not count that grade as passing. We also would like to see the number of passing grades, the number of failing grades and the number of invalid grades.

    Create two more test cases.

    Use following one in addition to the two you create.

    Grades Entered: Expected Results

    45

    90

    70

    87

    123 “That is not a valid grade!”

    100

    -1 You entered 4 passing grades.

    You entered one failing grade

    You entered one invalid grade.



    This is my code so far.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    main()
    {
        int score, sum=0;
    
        printf("Enter a score (-1 to quit)");
        scanf("%i", &score);
    	
        while (score != -1) {
        }
    
        system("pause");
    }
    Last edited by 2kaud; October 17th, 2018 at 02:13 AM. Reason: Added code tags

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,258

    Re: Calculating Grades program (Passing grades) (Failing Grades) in C++

    Quote Originally Posted by mikehunter View Post

    This is my code so far.


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    main() {
    	
    	int score, sum=0;
    
    	printf("Enter a score (-1 to quit)");
    	scanf("%i", &score);
    	
    	while (score != -1) {
    
    	}
    	
    	system("pause");
    }
    And it is what you called "code"???

    And where is what you had to implement in this "code" such as:
    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 (meaning either less than zero or greater than 100), present an error message to the user, and do not count that grade as passing. We also would like to see the number of passing grades, the number of failing grades and the number of invalid grades.
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,482

    Re: Calculating Grades program (Passing grades) (Failing Grades) in C++

    [When posting code, please use code tags for readable code. Go Advanced, select the formatted code and click '#'].

    Cheers!

    ... also your initial loop is not right. You are asking for the score to be entered before the start of the loop - so only one score is ever asked for and input. If this score is -1 then the program terminates straight away. If the entered score is not -1 then the program loops forever! Obtaining the score should be inside a loop.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.9)

  4. #4
    Join Date
    Feb 2017
    Posts
    360

    Re: Calculating Grades program (Passing grades) (Failing Grades) in C++

    Quote Originally Posted by mikehunter View Post
    It's for an online class and I didn't understand the lessons at all.
    To get started there are C++ tutorials on the internet, like here

    http://www.ntu.edu.sg/home/ehchua/pr...roduction.html

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)