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

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2007
Posts: 37
Reputation: radskate360 is an unknown quantity at this point 
Solved Threads: 0
radskate360 radskate360 is offline Offline
Light Poster

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

 
0
  #1
Jun 14th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 37
Reputation: radskate360 is an unknown quantity at this point 
Solved Threads: 0
radskate360 radskate360 is offline Offline
Light Poster

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

 
0
  #2
Jun 14th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,757
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 283
Lerner Lerner is offline Offline
Posting Virtuoso

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

 
0
  #3
Jun 15th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 585 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC