| | |
Program Seems to be right but still some confusion on output into columns
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2007
Posts: 37
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: May 2007
Posts: 37
Reputation:
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.
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.
•
•
Join Date: Jul 2005
Posts: 1,757
Reputation:
Solved Threads: 283
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.
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.
![]() |
Similar Threads
- A multilingual coded Hello World! thread (Legacy and Other Languages)
- Help a lurker (Java)
- triangles program (Java)
- run program and rename file script help please (Shell Scripting)
- code seems to stop executing (C++)
- Card program in C++ (C++)
- Stack Queue Fstream (C++)
Other Threads in the C++ Forum
- Previous Thread: Drag a window by its client area?
- Next Thread: Search for the Closer Number
Views: 585 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






