Programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • compsci
    New Member
    • Jan 2007
    • 32

    Programming

    I just don't understand my assignment. Can someone explain to me what I am suppose to be doing.
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by compsci
    I just don't understand my assignment. Can someone explain to me what I am suppose to be doing.
    what is the program specification?

    Comment

    • compsci
      New Member
      • Jan 2007
      • 32

      #3
      Write a program that does the following.
      1. Repeatedly read a student score (for an exam) and add it to a running sum. Count the number of scores entered. (We’ll assume that the scores are between 0 and 100.) Stop when the user enters a negative number. Output the sum and count of the scores.
      2. Define a function average that, passed the sum of the scores and the count of the scores, computes the average score, which it returns. In main, call this function just after the above loop, and output the average score that the function returns.
      3. Define a function validScore that, passed a score, returns true if the score is between 0 and 100 and otherwise returns false. Using this function, modify the loop that reads in the scores so that, if the score is not valid, it is echoed with a message saying that the score is invalid, and so that the score is counted and added to the sum only when it is valid. (Note that there is some redundancy as validScore is used here since the loop exits when a negative score is entered—so validScore is never passed a score that is invalid because it is negative.)
      4. Define a function letterGrade that, passed a valid score (one between 0 and 100), returns a letter grade according to the following schedule:
      ‘A’: 90 and above
      ‘B’: 80-89
      ‘C’: 70-79
      ‘D’: 60-69
      ‘F’: below 60
      Use this function to find the letter grade corresponding to each valid score and output the letter grade as soon as it is found. Keep a count of the number of each letter grade (‘A’-‘F’) and output each count at the end of the run.

      Comment

      • horace1
        Recognized Expert Top Contributor
        • Nov 2006
        • 1510

        #4
        Originally posted by compsci
        Write a program that does the following.
        1. Repeatedly read a student score (for an exam) and add it to a running sum. Count the number of scores entered. (We’ll assume that the scores are between 0 and 100.) Stop when the user enters a negative number. Output the sum and count of the scores.
        .
        initially just do part 1 - have a loop which reads number from the keyboard, if the number is negative exit the loop otherwise add the value to the running sum and increment the count of scores.

        when that is working move on to part 2, etc.

        Comment

        • compsci
          New Member
          • Jan 2007
          • 32

          #5
          Could you help me out with the code because I'm a beginner in C++.

          Comment

          • xuxf055
            New Member
            • Jan 2007
            • 6

            #6
            It is not difficult.
            You can do it with while and for sentence
            Try to do it firstly, then ask question, then somebody will help you and you will get improved.

            Comment

            • compsci
              New Member
              • Jan 2007
              • 32

              #7
              Code:
              int main()
              {
                 int n;
              
                 cout << "Enter a number:";
                 cin >> n;
              
                 while (n<=0)
                 {
                    cout << "Please a positive number";
                    cin >> n;
                 }
              
                 int product = 1;
                 for(int x = 1; x<=n; x++)
                 {

              Comment

              • RedSon
                Recognized Expert Expert
                • Jan 2007
                • 4980

                #8
                Originally posted by compsci
                int main()
                {
                int n;

                cout << "Enter a number:";
                cin >> n;

                while (n<=0)
                {
                cout << "Please a positive number";
                cin >> n;
                }

                int product = 1;
                for(int x = 1; x<=n; x++)
                {
                REPLY GUIDELINES
                Please follow these guidelines when responding.
                • Write in clear concise language using correct grammar and spelling
                • Use CODE tags around your code:

                  Code:
                  ..code goes here..
                • Do not link to other websites for promoting/traffic generation. Only link to helpful resources.

                Comment

                • compsci
                  New Member
                  • Jan 2007
                  • 32

                  #9
                  Can someone help me? I tried the first part but I don't know if it is right.

                  Comment

                  • compsci
                    New Member
                    • Jan 2007
                    • 32

                    #10
                    This is the cod that I have so far
                    Code:
                    int main()
                    {
                    int n;
                    
                    cout << "Enter a number:";
                    cin >> n;
                    
                    while (n<=0)
                    {
                    cout << "Please a positive number";
                    cin >> n;
                    }

                    Comment

                    • Ganon11
                      Recognized Expert Specialist
                      • Oct 2006
                      • 3651

                      #11
                      1. Repeatedly read a student score (for an exam) and add it to a running sum. Count the number of scores entered. (We’ll assume that the scores are between 0 and 100.) Stop when the user enters a negative number. Output the sum and count of the scores.

                      How do you think you would do this? What kind of a loop would you need? What would the end condition be? What do you need to do inside the loop?

                      Comment

                      • compsci
                        New Member
                        • Jan 2007
                        • 32

                        #12
                        I would need a for and while loop. That is all I know right now.

                        Comment

                        • christinamasalha
                          New Member
                          • Jan 2007
                          • 16

                          #13
                          Hello,
                          From what i can see you need to check your while condition. It is not correct.
                          The loop will never work because it will not be true after the initiall "n" is entered.
                          Double check it.


                          Hope that helps.
                          Christina

                          Comment

                          • compsci
                            New Member
                            • Jan 2007
                            • 32

                            #14
                            I'm having a hard time doing this program

                            Comment

                            • compsci
                              New Member
                              • Jan 2007
                              • 32

                              #15
                              I don't know what else to do. Somebody please help me

                              Code:
                              int main()
                              {
                              	cout << “Enter score” << endl;
                              	cin << n;
                              
                              	int countScores, sumScores, scores;
                              
                              for (scores = 0; n< 0;  countScores +1)
                              {
                                   n= i;
                                   cout << j << endl; 
                              
                              }

                              Comment

                              Working...