hässlichen code beseitigen
-
Habe alles in eine klasse geschrieben und da steht so oft pWorker...
darum wollt ich das ganze in eine WorkerMenu() function packen.dann sagt der mir aber das pWorker und *WorkerChoice nicht deklariert sind
wie kann ich das sonst machen damit dieser hässliche code wegkommt ?
switch(mChoice) { case 1: if(*WorkerChoice>0) { *WorkerChoice-=1; system("cls"); cout << "Vorname: "<< pWorker[*WorkerChoice].GetVname() <<endl << "Nachname: "<< pWorker[*WorkerChoice].GetNname() <<endl << "Alter: "<< pWorker[*WorkerChoice].GetAge() <<endl << "Lohn: "<< pWorker[*WorkerChoice].GetSelery() <<endl; } else { system("cls"); cout << "Vorname: "<< pWorker[*WorkerChoice].GetVname() <<endl << "Nachname: "<< pWorker[*WorkerChoice].GetNname() <<endl << "Alter: "<< pWorker[*WorkerChoice].GetAge() <<endl << "Lohn: "<< pWorker[*WorkerChoice].GetSelery() <<endl; } break; ...
-
dann sagt der mir aber das pWorker und *WorkerChoice nicht deklariert sind
nach dem, was wir da sehen können, stimmt das auch
-
class DynamicArray
{
private:
Worker *pWorker;
...public:
DynamicArray(int Startwert)
{
...
pWorker = new Worker[max];
};void GetthePushed()
{
...
unsigned int WorkerC;
cin >> WorkerC;
cin.clear();
int* WorkerChoice = new int(WorkerC);
...
switch(mChoice)
{
case 1:
if(*WorkerChoice>0)
{
*WorkerChoice-=1;
system("cls");
cout << "Vorname: "<< pWorker[*WorkerChoice].GetVname() <<endl
<< "Nachname: "<< pWorker[*WorkerChoice].GetNname() <<endl
<< "Alter: "<< pWorker[*WorkerChoice].GetAge() <<endl
<< "Lohn: "<< pWorker[*WorkerChoice].GetSelery() <<endl;
}
else
{
system("cls");
cout << "Vorname: "<< pWorker[*WorkerChoice].GetVname() <<endl
<< "Nachname: "<< pWorker[*WorkerChoice].GetNname() <<endl
<< "Alter: "<< pWorker[*WorkerChoice].GetAge() <<endl
<< "Lohn: "<< pWorker[*WorkerChoice].GetSelery() <<endl;
}
break;
}
...
-
ich würdma erstma
pWorker[*WorkerChoice] in einer eigenen variable vor dem switch speichern und im switch diese variable verwenden
und welchen sinn macht dasunsigned int WorkerC; cin >> WorkerC; cin.clear(); int* WorkerChoice = new int(WorkerC);