I have this program, which should give me the smallest original price of the item based on the input from the user.
There are some conditions, for example, if the quantity of the mask is more than 9 the price will be discounted by 10%, 15% if its more than 30 and 20% if it's more than 50. The result should give the answer Here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
int mprice; //price input
int mquantity; //quantity input
int n; //first input
int fee = 2000; //const fee
float finalprice;
float maskCalc(int price, int quantity) {
float holder = (float)(price - fee) / (float)(quantity);
if (quantity > 0) {
finalprice = holder;
}
//if between 10 and 30
else if (quantity > 9) {
finalprice = holder / 0.9;
}
//between 30 and 49
else if (quantity > 30) {
finalprice = holder / 0.85;
}
//more than 50
else if (quantity > 49) {
finalprice = holder / 0.8;
}
//less than ten
else {
finalprice = holder;
}
return finalprice;
}
int main()
{
cin >> n;
float arr[n];
// Input oruulah loop
for (int i = 0; i < n; i++) {
cin >> mprice >> mquantity;
x = maskCalc(mprice, mquantity);
arr[i] = x;
}
for (int i = 1; i < n; i++) {
if (arr[0] > arr[i]) {
arr[0] = arr[i];
}
}
printf("%.2f", arr[0]);
return 0;
}
I gave the input
3
5000 3
7000 10
3000 1
the answer was 555.56 which is correct, but when I give something like
3
2500 1
7000 10
3000 1
it is giving me 0.00 while I was expecting this to give me 500.00. Any help will be appreciated.
You need to check for the highest quantity first in your if-else switch, otherwise you always fall into the default (<10) case.
//more than 50
if (quantity >= 50) {
finalprice = holder / 0.8;
}
//between 30 and 49
else if (quantity >= 30) {
finalprice = holder / 0.85;
}
//if between 10 and 30
else if (quantity >= 10) {
finalprice = holder / 0.9;
}
//less than ten
else {
finalprice = holder;
}
Related
I was given a problem. In the problem I am suppose to take input current month, current year and current water level of a dam from user. There is a scale that from month march to august the water level increase by 150 feet each month and from sep to feb it decreases by 200 feet. Now I am supposed to tell in which month and year the Dam will have no water or 0 feet water level. I have made the below program using loops but I have to it with out loops/recursive function. I got the year by dividing the water level with avg_decrease in water level.You cans see the program that does what I want with loop.
#include<iostream>
using namespace std;
int main(){
int c_month, c_year, wlevel, avg_decrease;
cout<<"Enter current month number: ";
cin>>c_month;
cout<<"Enter current water level: ";
cin>>wlevel;
cout<<"Enter current year: ";
cin>>c_year;
avg_decrease = 300; //-25 each month, -300 each year
cout<<wlevel/avg_decrease<<endl;
int m = c_month, level = wlevel, y = c_year;
while(true){
if(x)
break;
for(int i =0;i<=12;i++){
if(level < 0){
x = true;
break;
}
else if(m >= 3 && m<=8){
level = level +150;
m++;
}
else{
level = level -200;
if(m == 12)
m=1;
else
m++;
}
}
y++;
}
cout<<y<<"\t"<<m<<endl;
}
I want to get the month and year in which the water level is 0 feet which is being printed in the last line without using the loops. I dont know how to implement the above program without using loops. If any one can help, it would be great.
Thanks in advance
test this and change code if my logic is wrong
#include<iostream>
using namespace std;
int main(){
int m, y, lev;
cout << "Enter current month number: ";
cin >> m;
cout << "Enter current year: ";
cin >> y;
cout << "Enter current water level: ";
cin >> lev;
int avg_year = 300; // average year decrease
int year_count = lev/avg_year; // how many entire years we will be decreasing for sure
lev = lev % avg_year; // how much level we still have after entire years have pass
if ((lev > 0) && (m <= 8) && (m >=2)) // march - aug we are adding +150 each month
{
int delta = (6 - m + 2); // how much times we should add +150
lev = lev + 150*delta;
m = m + delta;
}
if((lev > 0) && (m == 8)) // end of aug (sep = -200)
{
m++;
lev = lev - 200;
}
if((lev > 0) && (m == 9)) // end of sep (oct = -200)
{
m++;
lev = lev - 200;
}
if((lev > 0) && (m == 10)) // end of oct (nov = -200)
{
m++;
lev = lev - 200;
}
if((lev > 0) && (m == 11)) // end of nov (dec = -200)
{
m++;
lev = lev - 200;
}
if((lev > 0) && (m == 12)) // end of dec (jan = -200)
{
m = 1;
year_count++;
lev = lev - 200;
}
/*
in case at the beginning of the program m== 1 AND Level == (801 - 899)
2 years past and we are at m == 1 with level == (201 - 299)
februarry gives -200. So at the end of m==2, level == (1 - 99)
when we do march-december we gain +100 level
so in the beginning of the next year jan level will be 101-199
and since jan takes -200 from level. It is definitely next years jan
so we are just increasing year count
*/
if((lev > 0) && (m == 1)) // enf of jan (feb = -200)
{
lev = lev - 200;
if(lev <= 0)
m++;
else
year_count++;
}
cout << (y + year_count) << "\t" << m << endl;
}
UPD
this is bellow I think the right solution as I would do it with all the loops. I doubt it can be achieved just by plain code with no loops or recursion
#include<iostream>
using namespace std;
int level_func(int m, int y, int lev)
{
int ar[] = { -200, -200, 150, 150, 150, 150, 150, 150, -200, -200, -200, -200 };
int m_count = 0;
while (lev > 0)
{
m++;
m_count++;
if (m > 12)
m = 1;
lev = lev + ar[m - 1];
}
return m_count;
}
int main() {
int m, y, lev;
cout << "Enter current month number: ";
cin >> m;
cout << "Enter current year: ";
cin >> y;
cout << "Enter current water level: ";
cin >> lev;
int month_count = level_func(m, y, lev);
y = y + month_count / 12;
m = m + month_count % 12;
if (m > 12)
{
y++;
m = m - 12;
}
cout << y << "\t" << m << endl;
}
I worked on the solution myself and found a very efficient way to do it. I calculated total months required and got the total years from the month.The code is below
#include<iostream>
using namespace std;
int main(){
int exact_months,year = 0;
int c_month, c_year, wlevel, avg_decrease;
cout<<"Enter current month number: ";
cin>>c_month;
cout<<"Enter current water level: ";
cin>>wlevel;
cout<<"Enter current year: ";
cin>>c_year;
int mn;
exact_months = wlevel/25;
mn = (c_month+exact_months)%12;
if ((c_month+exact_months)%12 !=0 && c_month != 1)
year = 1;
year = exact_months/12+year;
cout<<"Date: "<<year+c_year<<":"<<mn;
}
I'm trying to learn how to find a rational approximation of a real number when both the numerator and denominator are constrained. I've looked at many pages now, including the following two, and learned about the continued fractions method, the Farey sequence, and the Stern-Brocot tree. However, in all of these examples, either the numerator or denominator are unconstrained.
Algorithm for simplifying decimal to fractions
https://gist.github.com/mikeando/7073d62385a34a61a6f7
Here's my situation:
I'm testing mixed-signal ICs.
In one of our tests, in order to find the IC's maximum operating frequency, the clock signal going into the IC is set to 12 MHz and continually decreased until the IC is able to run a simple digital sequence.
The test platform's main clock has a range of 25 to 66 MHz, and the function that sets it takes in a double.
In the current version of the test, it's set to a constant 50.0 MHz, then a function that divides that frequency is called in a loop. The divisor is an integer that can be anywhere between 1 and 4096.
However, this results in imprecise measurements.
The devices always pass at:
50 / 5 = 10 Mhz
50 / 6 = 8.333 MHz
If possible, to get more precise measurements, I'd like to be able to change the main clock's frequency AND the clock divisor in each loop iteration. That's why I'm trying to learn how to write something like a continued fractions algorithm with constraints to both the numerator and denominator. I'm envisioning something like this:
while(dFmax > dFmin)
{
std::pair<double, int> bestSettings = GetBestClkSettings(dFmax);
double dFreq = bestSettings.first;
int iDiv = bestSettings.second;
// Set up clock and timesets
clkset(dFreq);
clkdivide(iDiv);
// Run pattern
// ...
// Get results
// ...
dFmax -= 0.1;
}
Not only have I spent hours experimenting with the code in the second link, but I also tried writing a function that uses something like binary searching just to see what would happen. I'm fully aware that this is terrible code that I can't use to achieve my goals; I just wanted to show that I have been trying.
#include <iostream>
#include <stdio.h>
#include <cmath>
// The fraction struct and the main() function were largely taken from:
// https://gist.github.com/mikeando/7073d62385a34a61a6f7
struct fraction {
int n;
int d;
fraction()
{
this->n = -1;
this->d = -1;
}
fraction(int n, int d)
{
this->n = n;
this->d = d;
}
double asDouble()
{
double dReal = static_cast<double>(n) / static_cast<double>(d);
return dReal;
}
};
fraction ApproximateFrequency(double dTargetFreqMHz, double dTol)
{
fraction result;
if (dTargetFreqMHz < (25.0 / 4096) || dTargetFreqMHz > 66.0)
{
return result;
}
else if (dTargetFreqMHz >= 25.0 && dTargetFreqMHz <= 66.0)
{
result.n = static_cast<int>(dTargetFreqMHz);
result.d = 1;
return result;
}
int iFrqLo = 25;
int iFrqHi = 66;
int iDivLo = 1;
int iDivHi = 4096;
int iFrqCurr = (iFrqLo + iFrqHi) / 2;
int iDivCurr = (iDivLo + iDivHi) / 2;
double dFreq = static_cast<double>(iFrqCurr) / static_cast<double>(iDivCurr);
double dPrevFreq = 0;
int iNumIters = 1;
while (fabs(dTargetFreqMHz - dFreq) > dTol && fabs(dFreq - dPrevFreq) > 1e-8 && iNumIters < 25)
{
dPrevFreq = dFreq;
if (dFreq < dTargetFreqMHz)
{
// The frequency needs to be increased.
// The clock frequency could be increased:
int iFrqNew = (iFrqCurr + iFrqHi) / 2;
double dFrqIfClkInc = static_cast<double>(iFrqNew) / static_cast<double>(iDivCurr);
double dClkIncDiff = fabs(dTargetFreqMHz - dFrqIfClkInc);
// Or the divider could be decreased:
int iDivNew = (iDivLo + iDivCurr) / 2;
double dFrqIfDivDec = static_cast<double>(iFrqCurr) / static_cast<double>(iDivNew);
double dDivDecDiff = fabs(dTargetFreqMHz - dFrqIfDivDec);
// Find the option that produces a better result:
if (dClkIncDiff < dDivDecDiff && iFrqNew >= 25 && iFrqNew <= 66)
{
iFrqCurr = iFrqNew;
}
else if (dDivDecDiff < dClkIncDiff && iDivNew >= 1 && iDivNew <= 4096)
{
iDivCurr = iDivNew;
}
}
else
{
// The frequency needs to be decreased.
// The clock frequency could be decreased:
int iFrqNew = (iFrqLo + iFrqCurr) / 2;
double dFrqIfClkDec = static_cast<double>(iFrqNew) / static_cast<double>(iDivCurr);
double dClkDecDiff = fabs(dTargetFreqMHz - dFrqIfClkDec);
// Or the divider could be increased:
int iDivNew = (iDivCurr + iDivHi) / 2;
double dFrqIfDivInc = static_cast<double>(iFrqCurr) / static_cast<double>(iDivNew);
double dDivIncDiff = fabs(dTargetFreqMHz - dFrqIfDivInc);
// Find the option that produces a better result:
if (dClkDecDiff < dDivIncDiff && iFrqNew >= 25 && iFrqNew <= 66)
{
iFrqCurr = iFrqNew;
}
else if (dDivIncDiff < dClkDecDiff && iDivNew >= 1 && iDivNew <= 4096)
{
iDivCurr = iDivNew;
}
}
// See the frequency attainable with the current settings
dFreq = static_cast<double>(iFrqCurr) / static_cast<double>(iDivCurr);
std::cout << "prev = " << dPrevFreq << ", current = " << dFreq << std::endl;
iNumIters++;
}
result.n = iFrqCurr;
result.d = iDivCurr;
return result;
}
int main(int argc, char* argv[])
{
double dTargetFreqMHz = 20.0;
std::cout << "Target: " << dTargetFreqMHz << "\n\n";
double dTol = 0.05;
fraction mcf = ApproximateFrequency(dTargetFreqMHz, dTol);
printf("tol=%f, n/d = %d/%d = %f (err=%f)\n", dTol, mcf.n, mcf.d, mcf.asDouble(), mcf.asDouble()-dTargetFreqMHz);
}
Any advice or hints would be greatly appreciated. Thank you in advance.
Since your range is so constrained, you could just brute force it. There's only 172,032 possible combinations of numerator and denominator to check. The algorithm could be made more efficient by iterating from 25 to 66 and calculating the closest two denominators, in which case you only have to check 84 possibilities:
fraction ApproximateFrequency(double dTargetFreqMHz, double dTol)
{
fraction result;
if (dTargetFreqMHz < (25.0 / 4096) || dTargetFreqMHz > 66.0)
{
return result;
}
else if (dTargetFreqMHz >= 33.0 && dTargetFreqMHz <= 66.0)
{
result.n = static_cast<int>(dTargetFreqMHz);
result.d = 1;
return result;
}
double smallestError = 66.0;
int closestNum = 0;
int closestDenom = 0;
for (int num = 25; num <= 66; num++)
{
int denom = floor((double)num / dTargetFreqMHz);
if (denom >= 1 && denom <= 4096)
{
double freq = (double)num / double(denom);
double err = fabs(dTargetFreqMHz - freq);
if (err < smallestError)
{
closestNum = num;
closestDenom = denom;
smallestError = err;
}
if (denom <= 4095)
{
freq = (double)num / double(denom + 1);
err = fabs(dTargetFreqMHz - freq);
if (err < smallestError)
{
closestNum = num;
closestDenom = denom + 1;
smallestError = err;
}
}
}
}
result.n = closestNum;
result.d = closestDenom;
return result;
}
the dTol parameter isn't used so you could get rid of it.
Hi guys and thanks in advance
I'm struggling with a c++ program which should calculate the tax for a given income based on different tax for certain thresholds, like:
0% for first 10.000$
5% for another 10.000$
and 15% for the rest of $
Everything I've managed to write is this invalid (result is always -0.3) code:
double tax_calculator(double income) {
double result = 0;
// threshold is array for tax thresholds, e.g 10000 or 20000$
int tokens[4];
for (int i = 1, y = 0; i <= income; i++) {
if (i > treshold[y]) {
// assign i to temporary var
tokens[y] = i;
i = 1;
y++;
}
}
for (int z = 0; z < 4; z++)
// tax is array of base tax values, like 5, 10 and 15 (%).
result += tokens[z] * tax[z] / 100.0;
return result;
}
Hope you give me some advice :)
The key is that taxes are based on brackets, not individual values. You should think about them like a table:
min | max | pct
$0 | $10,000 | 0%
$10,000 | $20,000 | 5%
$20,000 | +inf | 15%
So if we define a bracket like:
struct bracket {
double min;
double pct;
};
We can use the next bracket's min to the the max. So in your case:
std::vector<bracket> brackets = { {0, 0.0}, {10000, 0.05}, {20000, 0.15} };
double income = ???;
double taxes = 0.0;
for (size_t i = 0; i < brackets.size(); ++i) {
double cur = (i == brackets.size() - 1) ? income : std::min(income, brackets[i+1].min);
cur = std::max(0.0, cur - brackets[i].min);
taxes += cur * brakcets[i].pct;
}
For an income of, say, $100000, the first line would set cur to be {10000, 20000, 100000}. The second line would reduce it to {10000, 10000, 80000}. And the last line would give you the taxes as {0.0, 500, 12000}... leading to a final result of $12,500.
I did it by myself already, but I want to know your opinion about it. Thanks.
double tax_calculator(double income) {
// temporary var to hold tokened-income
int var[Thresholds_amount] = { 0 };
for (int i = 0; i < Thresholds_amount; i++) {
// if income after subtraction is greater or equal to zero
if (income - Threshold_level[i] >= 0) {
// assign the entire threshold level to proper var
var[i] = Threshold_level[i];
// subtract the threshold level from income for real
income -= Threshold_level[i];
}
else {
// assign the rest of the value to proper var
var[i] = income;
// exit the loop
break;
}
}
double result = 0.0;
// consolidate all taxes
for (int y = 0; y < Thresholds_amount; y++)
result += var[y] * Base_tax[y] / 100.0;
return result;
}
Values for some variables that were created outside of the function:
const short Thresholds_amount = 4;
const int Threshold_level[Thresholds_amount] = { 5000, 10000, 20000, 35000 };
const int Base_tax[Thresholds_amount] = { 0, 10, 15, 20 };
I took some cues from the answer by #Barry and made some changes with the hope that it is an improvement over his answer.
#include <iostream>
#include <cstdlib>
#include <cfloat>
#include <algorithm>
struct bracket
{
// Use max in the bracket instead of min.
double max;
double pct;
};
int main(int argc, char** argv)
{
std::vector<bracket> brackets = { {10000.0, 0.0}, {20000, 0.05}, {DBL_MAX, 0.15} };
double income = atof(argv[1]);
double taxes = 0.0;
// There are no taxes if the income is less than 10000.0.
// There is no need to check for that bracket.
for (size_t i = 1; i < brackets.size(); ++i)
{
double cur = std::min(income, brackets[i].max);
taxes += (cur - brackets[i-1].max) * brackets[i].pct;
// If income is less than or equal to the current bracket's max,
// there is no need to compute any more tax amounts.
if ( income <= brackets[i].max )
{
break;
}
}
std::cout << "Income: " << income << ", tax amount: " << taxes << std::endl;
return 0;
}
These are my two errors:
error C2664: 'StudentMax' : cannot convert parameter 1 from 'int' to 'int []'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
This is my code, what do I need to fix?
// This program reads in data from a txt file, puts them in an array and calculates grades using that data.
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <fstream>
#include <string>
using namespace std;
float lab1, lab2, lab3, lab4, lab5, lab6, lab7, lab8, lab9, lab10;
float hw1, hw2, hw3, hw4, hw5, hw6, hw7, hw8;
float midterm = 3*(midterm);
float finall = 4*(finall);
float labScore;
float labAvg;
float hwScore;
float hwAvg;
float finalGrade;
string letterGrade;
string studentNameFirst;
ifstream inFile;
// prototypes for arrays
const char* names[10] = // kids names
{
"Mike",
"Carol",
"Greg",
"Marcia",
"Peter",
"Jan",
"Bobby",
"Cindy",
"Alice",
"Sam"
};
int* averages[10]; // number grades
string KidsLetterGrades[10]; // letter grades
int scores[4] = //elements comprising the final grade
{
labAvg,
hwAvg,
midterm,
finall
};
// function prototypes
int lowestScore(int scores[]);
int StudentMax(int scores[]);
void ComputeCourseGrade(int* averages[], string KidsLetterGrades[]);
void PrintInfo(const char* names[], string KidsLetterGrades[], int* averages[]);
int main(){
inFile.open("inputGrades.txt", ios::in); // opens input file
if (!inFile)
{
cout << "Cannot open input file. "; // file not open
return 1;
}
while (!inFile.eof( )) // until file ends
{
inFile >> studentNameFirst >> lab1 >> lab2 >> lab3 >> lab4 >> lab5 >> lab6 >> lab7 >> lab8 >> lab9 >> lab10 >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> hw8 >> midterm >> finall;
ComputeCourseGrade(averages, KidsLetterGrades);
PrintInfo(names, KidsLetterGrades, averages);
}
return 0;
}
void ComputeCourseGrade(int* averages, int scores[], string letterGrade)
{
for(int i = 0; i < 10; i++)
{
labScore = .2*((lab1 + lab2 + lab3 + lab4 + lab5 + lab6 + lab7 + lab8 + lab9 + lab10)/100)*100;
labAvg = (lab1 + lab2 + lab3 + lab4 + lab5 + lab6 + lab7 + lab8 + lab9 + lab10)/10;
hwScore = .1*((hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7 + hw8)/80)*100;
hwAvg = (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7 + hw8)/8;
finalGrade = ((labScore) + (hwScore) + (midterm) + (finall)); //attempting to make the lowest grade of the 4 things = to full credit for that grade aka dropping the lowest grade.... ideas on how?
lowestScore(scores);
finalGrade = finalGrade - lowestScore(scores);
finalGrade = finalGrade/4;
finalGrade = averages[i]; //assigns final grade in number form to array elements of average
if ( finalGrade >= 90)
letterGrade = "A";
else if (finalGrade >= 85)
letterGrade = "A-";
else if (finalGrade >= 80)
letterGrade = "B+";
else if (finalGrade >= 75)
letterGrade = "B";
else if (finalGrade >= 70)
letterGrade = "B-";
else if (finalGrade >= 65)
letterGrade = "C+";
else if (finalGrade >= 60)
letterGrade = "C";
else if (finalGrade >= 55)
letterGrade = "C-";
else if (finalGrade >= 50)
letterGrade = "D+";
else if (finalGrade >= 45)
letterGrade = "D";
else if (finalGrade >= 40)
letterGrade = "D-";
else letterGrade = "F";
letterGrade = KidsLetterGrades[i]; // assigns letter grades to array elements for kids letter grades
}
return;
}
int StudentMax(int averages[]) // to find student with highest class grade
{
int max = averages[0];
for( int m = 0; m < 10; m++)
{
averages[m];
if(averages[m] > max)
{ // finds maximum number among array elements
max = averages[m];
}
}
return max;
}
void PrintInfo(const char* names[], const char* KidsLetterGrades[], int averages[])
{
int count = 0;
StudentMax( averages[count]);
while (count < 10)
{
names[count];
cout << names[count] << KidsLetterGrades[count] << StudentMax( averages) << endl;
}
count++; // prints names then letter grades then averages
return;
}
int lowestScore(int scores[])
{
int lowest = scores[0];
for( int n = 0; n < 4; n++)
{
scores[n];
if(scores[n] < lowest)
{
lowest = scores[n];
}; //finds lowest number among array elements
}
return lowest;
}
You're passing an int to StudentMax, which expects an array (int[]).
You currently have StudentMax( averages[count]);, which is the offending line. You're not doing anything with that result, though, so just delete the line. That should fix both errors.
I am currently learning about pointers in my C++ class. The following code was slightly confusing but I eventually got it, my current problem is my logic.
I'm told I can find the number of students that have the same score without sorting or searching and using a single index but I can't for the life of me figure it out.
I have scores stored in scoresArray and the element number identifys which student it belongs to.
#include <iostream>
using namespace std;
const int maxStudents = 30;
void readScores(double[]);
void gradeCounter(double[],int&,int&,int&,int&,int&);
void sameScore(double[]);
int main()
{
int As = 0, Bs = 0, Cs = 0, Ds = 0, Fs = 0; // Distribution of scores
double scoreArray[maxStudents];
readScores(scoreArray);
gradeCounter(scoreArray, As, Bs, Cs, Ds, Fs);
system ("PAUSE");
return 0;
}
void readScores(double scoreArray[])
{
double *scorePTR;
scorePTR = scoreArray;
for(int count = 0; count < maxStudents; count++)
{
cout<<"Please enter score for student "<<count+1<<" or -999 to end.\n";
cin>>*(scorePTR+count);
if(*(scorePTR+count) == -999)
break;
}
}
void gradeCounter(double scoreArray[],int &As,int &Bs,int &Cs,int &Ds,int &Fs)
{
double *scorePTR2;
scorePTR2 = scoreArray;
for(int count = 0; count < maxStudents; count++)
{
if(scoreArray[count] >= 90)
As+=1;
else if(*(scorePTR2+count) >= 80 && *(scorePTR2+count) < 90)
Bs+=1;
else if(*(scorePTR2+count) >= 70 && *(scorePTR2+count) < 80)
Cs+=1;
else if(*(scorePTR2+count) >= 60 && *(scorePTR2+count) < 70)
Ds+=1;
else if(*(scorePTR2+count) >= 0 && *(scorePTR2+count) < 60)
Fs+=1;
}
}
void sameScore(double scoreArray[])
{
}
You can create a second array of 101 elements (from 0 to 100), initialize it all to 0, and use the current student's score as the index into this array
So, if the current student has a score of 87, then you would increment this_new_array[87] by 1.
In the end, the array at index X will contain the number of students that have score X.