samedi 7 décembre 2019

How can I format these outputs to create a table? C++

The output should be similar to a table, but I can't do it to be formatted like it. The table has 4 columns and the rows and inputs depend on the user. Please help me to format it. Thank you.

void number()

int b=0;
int groupChoice=0;
float ave[groupChoice];
int trials[groupChoice];
float result,sumRes,dAve;
int sumTry=0;
char choice;

cout << "\nNUMBER OF TRIALS" << endl;
cout << "\nHow many groups? ";
cin >> groupChoice;
for (int j=0;j<groupChoice;j++)
{
    cout << "Average distance for group " << j+1 << ": ";
    cin >> ave[j];
    cout << "No. of trials for group " << j+1 << ": ";
    cin >> trials[j];
}
cout << "\nGroups\t\tAve. Distance(x)\tNo. of trials(w)\tx(w)" << endl;
for (int i=0;i<groupChoice;i++)
{
    result=ave[i]*trials[i];
    cout << "Group " << i + 1 << "\t\t" << ave[i] << "\t\t\t" << trials[i] << "\t\t\t" << result << endl;
    sumTry=sumTry+trials[i];
    sumRes+=result;
}
cout << "\t\t\t\t\tSum = " << sumTry << "\t\tSum = " << sumRes << endl;
dAve = sumRes / sumTry;
cout << "Distance Average is " << dAve << endl << endl;

Aucun commentaire:

Enregistrer un commentaire