help with while loop

From: Ken (pianoqst_at_aol.com)
Date: 05/31/04


Date: 31 May 2004 06:45:41 -0700

Hi,
I am fairly new to C++ programming and I am trying to write a program
that will allow me to input the scores of a writing prompt given to my
students and output the percentage of students receiving the same
score. The scores are based on a rubric where the possible scores are
1, 2, or 3.
The code I am posting is just the input section. When I run the
program and input say, 16 scores of various 1s, 2s and 3s, the program
output says there were 16 score1s,
16 score2s and 16 score 3s. Could someone help me with this?
Thanks,
Ken

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <climits>

int main()
{
    int scoreCounter = 0; // number of grades entered
    int score1 = 0; // score values
    int score2 = 0;
    int score3 = 0;
    int result; // score entered by user
    
    while ( result != -1 ) { // loop until sentinel value read from
user

        cout << "Enter score, -1 to end: "; // prompt for input
        cin >> result; // read score from user

        if ( result = 1)
        score1 = score1 + 1; // add score to score1 total
        else
        if ( result = 2)
        score2 = score2 + 1; // add score to score2 total
        else
        if ( result = 3)
        score3 = score3 + 1; // add score to score3 total

        scoreCounter = scoreCounter + 1; // counts total number
of scores
     } // end while

     cout << "Total number of scores; " << scoreCounter << endl;
     cout << "Total number of score 1s: " <<score1 << endl;
     cout << "Total number of score 2s: " <<score2 << endl;
     cout << "Total number of score 3s: " <<score3 << endl;
     std::cin.ignore( INT_MAX, '/n');
     std::cin.get ();
     return 0;
}



Relevant Pages

  • Re: Portability: Harmony between PC and microcontroller
    ... int is the natural integer type for the system. ... You are, perhaps unintentionally, paraphrasing the standard in a way ... One of the things that you might not realize is that the C programming ... In the real world, most embedded systems have more complex jobs to do, ...
    (comp.lang.c)
  • Re: What will be the next MAJOR programming language for commercial use?
    ... Variants can be considered as such a common OO pattern that it is worth ... Int of int ... As lists are built-in, they can be decomposed in a pattern just as they are ... features found in other state-of-the-art programming languages. ...
    (comp.lang.misc)
  • Re: Bug/Gross InEfficiency in HeathFields fgetline program
    ... Maybe this is true in the sort of programming you do, ... you are storing a list of amounts of money as integers. ... int average ... the array, rounded towards zero. ...
    (comp.lang.c)
  • Re: beginner with programming, how to learn to debug and few C general questions
    ... I am first an accountant and decided to take on programming a few ... I have mainly been programming under Windows Xp DJGPP Dolorie... ... int main ... If you fix all of the above problems, it might fix whatever the issue ...
    (comp.lang.c)
  • Re: Lisp version of a Cism
    ... > int main{ ... This may be nice code for a newbie textbook on C programming, ... that include any kind of cross-platform portability, ... When we compare it to Lisp, we find that all the high level stuff is ...
    (comp.lang.lisp)