| | |
C++ File I/O
Thread Solved |
•
•
Join Date: Oct 2005
Posts: 11
Reputation:
Solved Threads: 0
Ok, yes, it is homework, and I've been tearing my hair out trying to get it to work, but eventually got there. The final thing I need to do is adjust the output that is sent to the console. It is supposed to be a histogram displaying the frequency of word lengths. I can get it to display, but its very bunched up. I think I'm supposed to use the setw() function, but am not sure where it is supposed to be used. The code is below, and any help would be appreciated.
<< moderator edit: added
Regards
Kevin
C++ Syntax (Toggle Plain Text)
int Displayhist (int scaledfrequency[]) { cout << setw(4); for (int row = 20 ; row >= 0; row--) { if (row == 20) { cout << "1.0 "; } else if (row == 0) { cout << "0.0 "; } else if (row == (20 / 2)) { cout << "0.5 "; } else { cout << " . "; } for (int k = 0; k < 20; k++) { if (scaledfrequency[k] >= row) { cout << "*"; } else { cout << " "; } } cout << endl; } for (int j = 0; j <= 20; j++) { cout << j; } cout << endl; }
[code][/code] tags >> Regards
Kevin
You need to make room for the numbers on the bottom, I'd guess. And that would mean you'd need to space out your columns:
for (int k = 0; k < 20; k++)
{
if (scaledfrequency[k] >= row)
{
cout << " * ";
}
else
{
cout << " ";
}
}
cout << endl;
}
cout << " ";
for (int j = 0; j <= 20; j++)
{
cout << setw(2) << j << ' ';
} “The essential notion of a socialist society is force.”
— Milton Friedman
— Milton Friedman
![]() |
Similar Threads
- connect to text file database (Visual Basic 4 / 5 / 6)
- Importing SQL Script File - Urgent !! (Database Design)
- Syntax for deleting specified file ( in C++) (C++)
- enabling file sharing (Windows NT / 2000 / XP)
- data file help (C)
- 81TB File Server (Networking Hardware Configuration)
Other Threads in the C++ Forum
- Previous Thread: Weird bug...
- Next Thread: Project
Views: 2416 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary c++ c/c++ calculator char class classes code compile compiler console constructor conversion convert count delete display dll dynamic encryption error file files form fstream function functions game givemetehcodez graph graphics gui homework i/o iamthwee input int lazy library linker list loop loops map math matrix memory newbie number object objects opengl output parameter pointer pointers problem program programming project qt random read reading recursion recursive reference sockets sort sorting spoonfeeding string strings struct student studio template templates text time tree variable vc++ vector video visual visualstudio win32 window windows winsock wordfrequency wxwidgets xml






