| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Syntax errors - Last Part of the program: Owner
Okay. I have a couple of switches in this function and I was wondering how I can fix this part of the program because it brings up a jump to switch case error.
This is the header: Code:
#ifndef JJAC_O_H
#define JJAC_O_H
class Users
{
public:
void users();
void ownerNames( string, string, string, string );
void viewExternal();
void workExternal();
};
#endif
This is the class file: Code:
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <fstream>
using namespace std;
#include "JJAC_O.h"
void Users::ownerNames( string own1, string own2, string own3, string own4 )
{
own1 = "Jessica";
own2 = "Jerald";
own3 = "Adeola";
own4 = "Ciara";
}
void Users::users()
{
int code;
cout << "Welcome to JJAC Gaming.\n"
<< "Please choose one of the following options:\n"
<< "1 - Player\n"
<< "2 - Employee\n"
<< "3 - Owner\n"
<< "4 - Exit\n";
cin >> code;
while( code != 4 )
{
switch( code )
{
case 1:
cout << "\nYou are not authorized to use this area."
<< "\nYou will be redirected to the exiting system.";
break;
case 2:
int employeeCode;
cout << "\nWelcome to JJAC Games - Employee Section.\n"
<< "\nFor security purposes, please input the company given code: ";
cin >> employeeCode;
switch( employeeCode )
{
case 1:
char yesno;
cout << "Welcome, Jessica Kennedy.\n"
<< "Would you like to modify the employee files( y/n )? ";
cin >> yesno;
cout << endl;
if( yesno == 'y' )
cout << "\nAccessing data now . . . .\n"
<< "\nUnable to access without password.\n"
<< "\nRedirecting you to secondary menu . . .\n";
break;
case 2:
char yesno2;
cout << "Welcome, Jerald Dawson.\n"
<< "Would you like to modify the employee files( y/n )? ";
cin >> yesno2;
cout << endl;
if( yesno2 == 'y' )
cout << "\nAccessing data now . . . .\n"
<< "\nUnable to access without password.\n"
<< "\nRedirecting you to secondary menu . . .\n";
break;
case 3:
char yesno3;
cout << "Welcome, Adeola Odunsi.\n"
<< "Would you like to modify the employee files( y/n )? ";
cin >> yesno3;
cout << endl;
if( yesno3 == 'y' )
cout << "\nAccessing data now . . . .\n"
<< "\nUnable to access without password.\n"
<< "\nRedirecting you to secondary menu . . .\n";
break;
case 4:
char yesno4;
cout << "Welcome, Ciara Carey.\n"
<< "Would you like to modify the employee files( y/n )? ";
cin >> yesno4;
cout << endl;
if( yesno4 == 'y' )
cout << "\nAccessing data now . . . .\n"
<< "\nUnable to access without password.\n"
<< "\nRedirecting you to secondary menu . . .\n";
break;
case 5:
char yesno5;
cout << "\nWelcome, current employee.\n"
<< "Would you like to view information( y/n )?\n";
cin >> yesno5;
if( yesno5 == 'y' )
viewExternal();
break;
case 6:
cout << "\nWelcome, former employee."
<< "\nYou need permission to access this information."
<< "\nPlease see an owner in order to access the information."
<< "\nThank you."
<< "\nRedirecting you to secondary menu . . .\n";
break;
case 7:
cout << "\nWelcome, new employee.\n"
<< "At this time, you need to view this information only\n"
<< "while a current employee or an owner is present.\n"
<< "\nThank you for your interests.\n";
break;
default:
cout << "\nAn incorrect employee code was entered."
<< "\nEnter a correct code at prompt.\n";
break;
}
case 3:
string owner;
string own1;
string own2;
string own3;
string own4;
ownerNames( own1, own2, own3, own4 );
cout << "\nPlease enter password: ";
cin >> owner;
if( owner != own1 || owner != own2 || owner != own3 || owner != own4 )
{
int misspass = 1;
while( misspass != 3 )
{
cout << "\nIncorrect password."
<< "\nAttempt " << misspass << " of 3"
<< "\nEnter a correct password: ";
cin >> misspass;
misspass++;
}
}
if( owner == own1 || owner == own2 || owner == own3 || owner == own4 )
cout << "Welcome, " << owner << ".\n"
<< "\nPlease enter data into the file: ";
workExternal();
break;
default:
cout << "Incorrect code. Try again:";
break;
}
}
void Users::workExternal()
{
ofstream outJJACFile( "JJAC.dat" );
if( !outJJACFile )
{
cerr << "File could not be opened.";
exit( 1 );
}
double pay;
string position;
string name;
cout << "Please enter the employee's name, position, and pay: ";
cin >> name >> position >> pay;
while( cin >> name >> position >> pay )
{
outJJACFile << name << ' ' << position << ' ' << pay;
cout << "?";
}
}
void Users::viewExternal()
{
ifstream inJJACFile( "JJAC.dat", ios::in )
if( !inJJACFile )
{
cerr << "File could not be opened.";
exit( 1 );
}
cout << "\nPulling up data: \n"
cout << "Name of Employee" << setw( 5 ) << "Position" << setw( 5 ) << "Pay"
<< endl << fixed << showpoint;
do
{
cout << left << setw( 10 ) << name << setw( 13 ) << position
<< setw( 7 ) << setprecision( 2 ) << right << pay << endl;
} while( inJJACFile >> name >> position >> pay )
}
These are the errors: Code:
JJAC_O.cpp: In member function `void Users::users()':
JJAC_O.cpp:164: jump to case label
JJAC_O.cpp:136: crosses initialization of `std::string own4'
JJAC_O.cpp:135: crosses initialization of `std::string own3'
JJAC_O.cpp:134: crosses initialization of `std::string own2'
JJAC_O.cpp:133: crosses initialization of `std::string own1'
JJAC_O.cpp:131: crosses initialization of `std::string owner'
JJAC_O.cpp:171: declaration of `void Users::workExternal()' outside of class is
not definition
JJAC_O.cpp:171: syntax error before `{' token
JJAC_O.cpp:174: `outJJACFile' undeclared (first use this function)
JJAC_O.cpp:174: (Each undeclared identifier is reported only once for each
function it appears in.)
Internal compiler error: Error reporting routines re-entered.
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat.com/bugzilla/> for instructions.
Please help if possible. Thank you. |
|
#2
|
||||
|
||||
|
dont forget to put a break after the nested switch in case 2
Code:
case 2:
int employeeCode;
cout << "\nWelcome to JJAC Games - Employee Section.\n"
<< "\nFor security purposes, please input the company given code: ";
cin >> employeeCode;
switch( employeeCode )
{
//blah blah blah
}
break;
__________________
|
|
#3
|
|||
|
|||
|
Okay. That didn't work so I took out the default case, I know it's a bad idea, and after solving the errors I knew got these syntax errors:
Code:
JJAC_O.cpp: In member function `void Users::users()':
JJAC_O.cpp:169: declaration of `void Users::workExternal()' outside of class is
not definition
JJAC_O.cpp:169: syntax error before `{' token
JJAC_O.cpp:172: `outJJACFile' undeclared (first use this function)
JJAC_O.cpp:172: (Each undeclared identifier is reported only once for each
function it appears in.)
JJAC_O.cpp: In member function `void Users::viewExternal()':
JJAC_O.cpp:216: syntax error before `}' token
JJAC_O.cpp:211: confused by earlier errors, bailing out
for this program: Code:
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <fstream>
using namespace std;
#include "JJAC_O.h"
void Users::ownerNames( string own1, string own2, string own3, string own4 )
{
own1 = "Jessica";
own2 = "Jerald";
own3 = "Adeola";
own4 = "Ciara";
}
void Users::users()
{
int code;
cout << "Welcome to JJAC Gaming.\n"
<< "Please choose one of the following options:\n"
<< "1 - Player\n"
<< "2 - Employee\n"
<< "3 - Owner\n"
<< "4 - Exit\n";
cin >> code;
while( code != 4 )
{
switch( code )
{
case 1:
cout << "\nYou are not authorized to use this area."
<< "\nYou will be redirected to the exiting system.";
break;
case 2:
int employeeCode;
cout << "\nWelcome to JJAC Games - Employee Section.\n"
<< "\nFor security purposes, please input the company given code: ";
cin >> employeeCode;
switch( employeeCode )
{
case 1:
char yesno;
cout << "Welcome, Jessica Kennedy.\n"
<< "Would you like to modify the employee files( y/n )? ";
cin >> yesno;
cout << endl;
if( yesno == 'y' )
cout << "\nAccessing data now . . . .\n"
<< "\nUnable to access without password.\n"
<< "\nRedirecting you to secondary menu . . .\n";
break;
case 2:
char yesno2;
cout << "Welcome, Jerald Dawson.\n"
<< "Would you like to modify the employee files( y/n )? ";
cin >> yesno2;
cout << endl;
if( yesno2 == 'y' )
cout << "\nAccessing data now . . . .\n"
<< "\nUnable to access without password.\n"
<< "\nRedirecting you to secondary menu . . .\n";
break;
case 3:
char yesno3;
cout << "Welcome, Adeola Odunsi.\n"
<< "Would you like to modify the employee files( y/n )? ";
cin >> yesno3;
cout << endl;
if( yesno3 == 'y' )
cout << "\nAccessing data now . . . .\n"
<< "\nUnable to access without password.\n"
<< "\nRedirecting you to secondary menu . . .\n";
break;
case 4:
char yesno4;
cout << "Welcome, Ciara Carey.\n"
<< "Would you like to modify the employee files( y/n )? ";
cin >> yesno4;
cout << endl;
if( yesno4 == 'y' )
cout << "\nAccessing data now . . . .\n"
<< "\nUnable to access without password.\n"
<< "\nRedirecting you to secondary menu . . .\n";
break;
case 5:
char yesno5;
cout << "\nWelcome, current employee.\n"
<< "Would you like to view information( y/n )?\n";
cin >> yesno5;
if( yesno5 == 'y' )
viewExternal();
break;
case 6:
cout << "\nWelcome, former employee."
<< "\nYou need permission to access this information."
<< "\nPlease see an owner in order to access the information."
<< "\nThank you."
<< "\nRedirecting you to secondary menu . . .\n";
break;
case 7:
cout << "\nWelcome, new employee.\n"
<< "At this time, you need to view this information only\n"
<< "while a current employee or an owner is present.\n"
<< "\nThank you for your interests.\n";
break;
default:
cout << "\nAn incorrect employee code was entered."
<< "\nEnter a correct code at prompt.\n";
break;
}
break;
case 3:
string owner;
string own1;
string own2;
string own3;
string own4;
ownerNames( own1, own2, own3, own4 );
cout << "\nPlease enter password: ";
cin >> owner;
if( owner != own1 || owner != own2 || owner != own3 || owner != own4 )
{
int misspass = 1;
while( misspass != 3 )
{
cout << "\nIncorrect password."
<< "\nAttempt " << misspass << " of 3"
<< "\nEnter a correct password: ";
cin >> misspass;
misspass++;
}
}
if( owner == own1 || owner == own2 || owner == own3 || owner == own4 )
cout << "Welcome, " << owner << ".\n"
<< "\nPlease enter data into the file: ";
workExternal();
break;
}
}
void Users::workExternal()
{
ofstream outJJACFile( "JJAC.dat" );
if( !outJJACFile )
{
cerr << "File could not be opened.";
exit( 1 );
}
double pay;
string position;
string name;
cout << "Please enter the employee's name, position, and pay: ";
cin >> name >> position >> pay;
while( cin >> name >> position >> pay )
{
outJJACFile << name << ' ' << position << ' ' << pay;
cout << "?";
}
}
void Users::viewExternal()
{
ifstream inJJACFile( "JJAC.dat", ios::in );
if( !inJJACFile )
{
cerr << "File could not be opened.";
exit( 1 );
}
string name;
string position;
double pay;
cout << "\nPulling up data: \n";
cout << "Name of Employee" << setw( 5 ) << "Position" << setw( 5 ) << "Pay"
<< endl << fixed << showpoint;
do
{
cout << left << setw( 10 ) << name << setw( 13 ) << position
<< setw( 7 ) << setprecision( 2 ) << right << pay << endl;
} while( inJJACFile >> name >> position >> pay )
}
Last edited by CDCAREY089 : December 2nd, 2008 at 09:20 AM. Reason: Replacing old text with new program text |
|
#4
|
||||
|
||||
|
You're missing a closing bracket somewhere in your users() function.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Syntax errors - Last Part of the program: Owner |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|