I am not exactly sure as to why the program is not taking in the input I give the program and put any numbers that were given into an array.
What I have to do:
Have a while statement that will abort after 10 inputs
Accumulate all numbers entered
display total of all numbers
display average
display titles for user to understand what is going on onscreen
anything that is displayed or typed in must be placed in the txt file
usingnamespace std;
std::ofstream ofs("prog12.txt", std::ofstream::out);
class programming
{
private:
int variable;
int temp;
int bypass;
int data_array[10];
int count;
int num_counter = 0;
int total = 0;
public:
int program_counter = 0;
int program_counterSHOWN = 0;
void input_value()
{
ofs << "Please enter a number : ";
while (!(cin >> variable))
{
ofs << "Must be a number : ";
ofs << endl;
cin.clear();
cin.ignore(100, '\n');
}
ofs << endl;
ofs << "You inputed: " << variable;
///////////////////////////////////////////////////////////
//COUNTING HOW MANY TIMES THE USER HAS INPUTED A NUMBER///
/////////////////////////////////////////////////////////
program_counterSHOWN++;
data_array[num_counter] = variable;
num_counter++;
ofs << endl;
ofs << endl;
//////////////////////////////////////////////////////
}
/////////////////////////////////////////////
//SHOWING HOW MANY NUMBERS ARE IN THE DATA//
///////////////////////////////////////////
void output_value()
{
ofs << "You have " << program_counterSHOWN << " number(s) in your data, your maximum is 10.";
ofs << endl;
ofs << endl;
ofs << "--------------------------------------------------------------------------------------";
ofs << endl;
ofs << endl;
}
void average()
{
for (int count3 = 0; count3 < num_counter; count3++)
{
total = data_array[count3] + total;
}
total = (total / num_counter);
ofs << "The average number of the data is : " << total;
ofs << endl;
ofs << endl;
}
};
int main()
{
programming object;
char retry = 'y';
while (object.program_counter < 10 && retry == 'Y' || retry == 'y')
{
object.input_value();
ofs << endl;
object.output_value();
ofs << endl;
cout << endl;
cout << "Want to add more? (Type 'Y' for yes, any other input will be no): ";
cin >> retry;
}
object.sorting_array();
ofs << endl;
object.average();
}