Ok, i got it so i can get Create to work, but before i finish that one, i want to finish the rest of the options. I get an illegal break error, what is with that? And also, what is good and bad about my code? like what do i now need in it?
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int name;
int Exit;
constint SENTINEL = Exit;
char userSelect;
cout <<"*******Final Project*******\n\n\n"<< endl;
cout << "\n Please select from the three options.\n"
<< "B to Begin\n"
<< "C to Create\n"
<< "E to Exit"
<< endl;
cin >> userSelect;
switch (userSelect)
{
case'C': case'c':
cout << "Choose a Name you would like to use and type exit to quit.\n";
cin >> name;
cout << " " <<endl;
cout << "\n" <<endl;
cout << "\nChose your Race."<<endl;
cout << "!Dwarf! !Orc! !Minotuar! !Human! !Elf!"<<endl;
break;
}
case'B': case'b':
{
cout << "Type in your user name\n."
<< "Type in your password.\n"
<< endl;
}
return 0;
}
Some problems I noticed:
- Your indentation is inconsistent, which makes it confusing to read and therefore harder to see problems.
- Your case 'B' seems to be outside of your switch block.
It is the case for 'B' and 'b' they are outside the block.
A few suggestions:
1.) your Exit variable hasn't been initialized. doing:
1 2
int Exit = 0; //or whatever you want this to initialize.
constint SENTINEL = Exit;
could make your code less problematic.
An alternative for using constants is to use global definitions/macro.
#define SENTINEL 0
2.)When making a switch statement, I would suggest using a default case. You may opt to error/input check before the switch statement, but from my experience, it is easier and simpler to do this inside the default case.
EDIT: I do not see where is the file I/O in your code.