944,214 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 692
  • C++ RSS
Jun 14th, 2007
0

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

Expand Post »
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.
Similar Threads
Reputation Points: 34
Solved Threads: 0
Light Poster
radskate360 is offline Offline
37 posts
since May 2007
Jun 14th, 2007
0

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

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.
Reputation Points: 34
Solved Threads: 0
Light Poster
radskate360 is offline Offline
37 posts
since May 2007
Jun 15th, 2007
0

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

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.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Drag a window by its client area?
Next Thread in C++ Forum Timeline: Search for the Closer Number





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC