help with while loop
From: Ken (pianoqst_at_aol.com)
Date: 05/31/04
- Next message: Chris \( Val \): "Re: A newbie question"
- Previous message: Maya: "Re: Conversion from String to SizeType"
- Next in thread: Aggro: "Re: help with while loop"
- Reply: Aggro: "Re: help with while loop"
- Reply: Aggro: "Re: help with while loop"
- Reply: Francis Glassborow: "Re: help with while loop"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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;
}
- Next message: Chris \( Val \): "Re: A newbie question"
- Previous message: Maya: "Re: Conversion from String to SizeType"
- Next in thread: Aggro: "Re: help with while loop"
- Reply: Aggro: "Re: help with while loop"
- Reply: Aggro: "Re: help with while loop"
- Reply: Francis Glassborow: "Re: help with while loop"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|