write/read from file.

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?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>

using namespace std;

	
	

int main() 
{
	
	int name;
	int Exit;
	const int 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.
const int 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.
Last edited on
Topic archived. No new replies allowed.