954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Program Seems to be right but still some confusion on output into columns

My program seems all correct but when I run the program my outputs are all what they need to be but I just cant seem to figure out how to send my output into 5 seperate columns. After reading the teachers notes I am more confused with his explanation on how to output to columns.

Here is the Directions:

Write a program that will generate an unknown (between 93 and 139) count of random numbers whose values fall between 147 and 206. Calculate the average to 2 decimal places and standard deviation to 3 decimals. On the monitor display only the count of numbers, the mean, and the standard deviation. Then after you have displayed alll of that information list them again in 5 columns in order from high to low and then have skipped two spaces.

Here is what I have so far:

srand((unsigned int) time (NULL));
int first, second;
int high, low, high2, low2;
int number, number2;
int total = 0, total2 = 0, overall = 0;
double average, deviation;
high = 139;
low = 93;
high2 = 206;
low2 = 147;


for (first=0; first<1; first++)
{
number = rand()%(high-low+1)+low;
}


for (second=0; second < number; second++)
{
number2 = rand()%(high2-low2+1)+low2;
total = number2 * number2;
total2 = total2 + number2;
overall = overall + total;
cout << number2 << endl;
}



average = ((double)total2 / (double)second);
deviation=sqrt(((double)overall/(double)second)-(((double)total2*(double)total2)/((double)second*(double)second)));

cout << fixed << showpoint << endl;
cout << second << endl;
cout << setprecision ( 2 ) << average << endl;
cout << setprecision ( 3 ) << deviation << endl;

Any assisntance you can give me on seperating my outputs into 5 seperate columns would be greatly appreciated.

radskate360
Light Poster
37 posts since May 2007
Reputation Points: 34
Solved Threads: 0
 

Also I have had a bit of direction from the teachers handouts

EX:
int second;
if(second % 5 == 0)
putchar('\n');
cout << number2;
}

But what happens if second%5 !=0, is can it still out put like

say second is 24

2 5 6 7 11
3 5 11 6 13
5 4 2 8 12
0 9 14 8 7
12 4 5 6

and not completly fill the coulumns, by goal is to get my output to output into columns and output to 5 columns no matter how many numbers there are.

radskate360
Light Poster
37 posts since May 2007
Reputation Points: 34
Solved Threads: 0
 

You will need to store each value of number2 in a container as it's generated. When all the values of number2 have been generated then sort the container from high to low. Then use a loop using a counter (you could use second to do that) that ranges from 1 to less than or equal to number to print all the values of number2 stored in the container 5 values per line. If the loop counter % 5 equals zero then start a new line. If number % 5 is not equal to zero then the last line won't have 5 values in it.

As a learning experience when you have completed the task change the loop counter in the print out loop to range from 0 to less than number to see what difference it makes and try to explain why there is a difference in the appearance of the print out.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You