Hello, I am currently trying to write a program that will calculate some basic statistics for a programming assignment. I know and understand the rules pertaining to assignment questions, and I would greatly appreciate any helpful hints that could be provided. Basically my problem comes when I am both making the count of a certain amount of subjects in a fictional drug trial and when I am calculating the mean. This is because my code is not reading the first character of a line of data from the input file that I have, thus the count for number of subjects is short one and the mean is lacking that data point. Code to follow
/*-----------------------------------------------------------------
-Precondition: The file attached to drug_information has been opened
-successfully and contains the data related to teamocil's side effect
-information. data_array[] has been declared and initialized to zero.
-LENGTH is the global constant for the array and includes all positions
-for possible side effect levels. subject_count has been passed as a
-referenced parameter for the array.
-Postcondition: data_array now contains a value for the frequency of
-each side effect rating level.
*/
void create_histogram(ifstream& drug_information, int data_array[], int LENGTH, double& subject_count)
{
int side_effect_info = 0;
while (!drug_information.eof()){
//Extracts whole characters from the data file and places them
//in the variable side_effect_info.
drug_information >> side_effect_info;
cout << side_effect_info << endl;
//cout << side_effect_info << " "; //Checking that the file read in data
//Following line increments the value at a particular
//index if and only if the number was encountered. This
//gives a frequency value for the number at the index.
data_array[side_effect_info]++;
subject_count++;
}
}
This setup is showing that for every instance of a number that the loop encounters it will then increment the value in that index location.
In the full program "data_array[]" has been initialized with const int LENGTH = 11. This is to include side effect rating scores from 0 to 10.
My confusion pertains to why the program is not reading the first digit from the data line. For instance in the example below, it does not read the numeral 6.
Example Data Line:
6 2 9 8 5 1 0 1 4 5 10 0 5 8 3 0 2 0 0 10