The question says it all, really. I am not sure what the problem is. I am new to classes; my practical experience with them is close to the Nile, but I read a lot about them.
I created an ECard class with the following constructor
ECard::ECard( int bankNum, int PIN ) { m_BankNum = new int; m_PIN = new int; m_Barred = new bool; m_Amount = new double; *m_BankNum = bankNum; *m_PIN = PIN; *m_Barred = false; *m_Amount = 100.0; }
and I initialize with an EC card( 12345, 54321 )
I also have a display() member function that simply prints all the member variables BankNum, PIN, Barred and Amount.
When I call this card.display () function in my main function, the output is what I expected.
However, when it goes into my loop:
card.display(); while( true ) { mainScreen( card ); choice = readInput(); card.display(); if( !doChoice( choice, card ) ) { cout << "Bad input- repeat!" << endl; } }
and I'm trying to print variables in my doChoice () function, I get garbage. All my variables have mixed up the settings. My Banknumber is that the PIN is really a large negative number (not MIN), locked suddenly set correctly, and there is 0 money in my account, even if the jumper and amount were never explicitly set by me somewhere outside of the constructors.
bool doChoice( int choice, ECard card ) { int inputPIN; int inputAmount; card.display(); switch( choice ) { case 1: cout << "PIN Eingeben: "; inputPIN = readInput(); cout << "\nBetrag Eingeben: "; inputAmount = readInput(); karte.aufladen( inputAmount, inputPIN ); return true;
I apologize if some of the member functions and outputs are still in German. This should not be important in any case (I like to write all my homework in English in any case, since I will probably program for international companies, but my teacher is really demanding and omits my class if I program outside of it expectations) p>
The variables are already mixed up before it even enters the switch, so the part should be just rhetoric. I only see the problem with passing the map object, although I do not know why this would be a problem. I donβt know how to fix it, just I just send each participant? Create a pointer to an object and send it? I mean, I used to pass a map object, and another function did not give me garbage. Only this one.
On the final note, if there is a sudden mistake in the syntax, it is because I quickly translated all my functions and members into English, and I may have missed capitalization somewhere or whatnot. Please do not pay attention to them, the syntax is correct and the program works, it just displays garbage values.