I am taking a C++ programming class for college, and i am working on my final of my choice. I choose to make a simple program in which that i could make an account for a rpg game. I have got the beginning options down, and am working on the choices they have to select. That is where im stuck. What is the format that i should use to do this? my code is as follows so far.
#include <iostream>
#include <string>
using namespace std;
int printStars();
int number;
int name;
char userSelect, Begin, Create, Exit;
int main()
{
printStars();
cout <<"*******Final Project*******\n\n\n"<< endl;
printStars();
int item0;
cout << "\n Please select from the three options." << endl;
//TELLS USER TO PICK OPTION
cout << "\n B to Begin"
//OPTION A
<< "\n C to Create"
//OPTION B
<< "\n E to Exit" << endl;
//OPTION C
cin >> item0;
cout <<endl;
cin >> Begin;
cout << endl;
cin >> item0 << " " <<endl;
switch (userSelect)
case 'C':
cout << "Choose a Name you would like to use.";
cin >> name;
cout << " " <<endl;
cout << "\n" <<endl;
You need to pay attention to two things:
1) what - type - of thing is being manipulated
2) what - order - things are manipulated
For example, 'item0' is an integer, but you instructed the user to input letters ('B', 'C', or 'E'). That will fail. I would get rid of all variables except 'char userSelect' and move 'userSelect' inside the main() function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main()
{
char userSelect;
...
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'B': case'b':
...
Make sense?
Now, inside your 'case' clauses you can ask for and gather extra information if you need.
i would use the toupper function on your userselect. include iostream if you have not. then you wont have to check for both B b C c E e ect. since it will make the letter uppercase if its not.