How do I get the student names in all lowercase chars except the first letter which is capitalized?

#include <fstream>
#include <stdlib.h>
#include <time.h>
using namespace std;

int main() {
//  Step 1: Declare
	ofstream OutFile;
	int NumStudents;
	int NumChar;
	int NewScore;
	char NewChar;
//  Step 2: Initialize
	OutFile.open("C:/Scores.dat");
	srand((unsigned) time(NULL));
//  Step 3: Solve
	// Write number of weights and the weights
	OutFile << 3 << ' ' << 50 << ' ' << 40 << ' ' << 10 << endl;
	// Determine the number of students
	NumStudents = 10 + rand() % 10;
	// For each student write the last name and the scores for the name
	for (int I = 0; I < NumStudents; I++) {
		// Write the name
		NumChar = 5 + rand () % 5;
		for (int J = 0; J < NumChar; J++) {
			NewChar = 65 + rand() % 26;
			OutFile << NewChar;
		}
		OutFile << ' ';
		// Write scores
		for (J = 0; J < 3; J++) {
			NewScore = 50 + rand () % 51;
			OutFile << NewChar;
		}
		OutFile << ' ';
		// Write the scores
		for (J = 0; J < 3; J++) {
			NewScore = 50 + rand () % 51;
			OutFile << NewScore << ' ';
		}
		OutFile << endl;
	}
	// Step 4: Wrapup
	OutFile.close();
	return 0;
}

Recommended Answers

All 3 Replies

Use Loop to deal with names , and Ascii to convert the first letter to capital one

ooooh... what?? :?:

If you were reading names from a file and wanted to make them prettier you could use strlwr() and the like, but here you are manufacturing totally random names in a loop, so you could do something like this (modifying your loop):

for (int J = 0; J < NumChar; J++) {
    if (J == 0)
        NewChar = 'A';
    else
        NewChar = 'a';
    NewChar += rand() % 26;
    OutFile << NewChar;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.