| | |
C++ File I/O
Please support our C++ advertiser: Intel Parallel Studio Home
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 << ' ';
} "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
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
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






