@TAZO
In the loop, I'm trying to tell
char Choice;
what I selected. The reason I'm doing it in a loop is because there is no way of telling exactly how many students the user will input. So... it will say:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
switch (Choice)
{
case '1':
cout << "**'Change Names' selected**" << endl;
cout << "Choose 1 Student from below:" << endl;
for (short x = 0; x < MAX; x++)
cout << x + 1 << " - " << worms1 [x].Name << endl;
cout << "Choice: ";
cin.get (Choice);
if (! (Choice == '\n'))
cin.ignore ();
|
The code above will display all the students inputted. Then it helps you out by telling you what number corresponds to them. After inputting the number in
char Choice
, it's pretty hard to determine which student is which since you can't determine how many students will be present from the beginning of the program. This is where the loop comes in:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
char*numLetter = NULL;
for (short x = 0; x < MAX; x++)
{
itoa (x + 1, numLetter, 10);
if (Choice == *numLetter)
{
cout << "'" << worms1 [x].Name << "' selected" << endl;
cout << "Type new name for this student: ";
cin.getline (worms1 [x].Name, 80);
cout << "New Name for student #" << x << "is " << worms1 [x].Name << endl;
}
|
The reason for creating a constant pointer is because the
itoa
object needs one of its arguments to be a constant holder. Now... the loop starts.
itoa (x + 1, numLetter, 10)
... in this case,
x = 0
. So... 1 will be inputted into the pointer in binary mode. So... then if
numLetter == Choice
, it'll be able to change the name of the student I selected before the loop. The loop continues until it finds the correct number. The only problem is... when the
itoa
section starts, the program crashes. I couldn't get past this part because somehow
itoa
is incompatible with C++. Is there a different method or am I missing something?