Na wstępie chciałbym się przywitać, więc - siemanko wszystkim ;)
Od niedawna uczę się programowania w c++ i natrafiłem na problem w moim kodzie. Program ma wyświetlać opcje wyboru, po czym po wybraniu odpowiedniej pokazać kolejne opcje, w tym opcję powrotu. Problem polega na tym, że po wybraniu opcji i powrocie nie mogę ponownie wybrać innej. Wygląda to mniej więcej tak:
Wybierz opcję:
1
2
: wybieram 2
Wybierz podopcje:
1
2
0 - powrot
: Wybieram 0
ponownie wybierz opcje:
1
2
i w tym momencie co bym nie wpisał, ciągle każe mi wybrać opcję. Powstała jakaś pętla, ale nie mogę znaleźć błędu. Dodam tylko, że ten problem występuje tylko na poziomie pierwszym. Kiedy wybiorę opcję na poziomie 2-gim i 3-cim, bez problemu wraca do poz. 2 i wchodzi w inne opcje do poziomu 3.
Mam nadzieję, że w miarę jasno to opisałem :D
oto kod:
#include <iostream>
using namespace std;
main ()
{
int d=1, d2=1, d3=1;
while (d)
{
cout << "Marka:" << endl << "BMW - 1" << endl << "Opel - 2" << endl << "Koniec - 0" << endl;
cout << "Podaj numer: ";
cin >> d;
cout << endl << endl;
switch (d)
{
case 1:
while (d2)
{
cout << "E39 - 1" << endl << "E46 - 2" << endl << "Powrot - 0" << endl;
cout << "Podaj numer: ";
cin >> d2;
cout << endl << endl;
switch (d2)
{
case 1:
cout << "E39 sratatata" << endl << endl;
cout << "Powrot - 0" << endl << "Koniec - 1" << endl;
cout << "Podaj numer: ";
cin >> d3;
cout << endl << endl;
break;
case 2:
cout << "E46 sratatata" << endl << endl;
cout << "Powrot - 0" << endl << "Koniec - 1" << endl;
cout << "Podaj numer: ";
cin >> d3;
cout << endl << endl;
break;
default:
if (d2!=0)
{
cout << "Brak opcji: " << d2 << endl << endl;
}
else
{
cout << endl << endl;
}
break;
}
}
break;
case 2:
while (d2)
{
cout << "Astra - 1" << endl << "Omega - 2" << endl << "Powrot - 0" << endl;
cout << "Podaj numer: ";
cin >> d2;
cout << endl << endl;
switch (d2)
{
case 1:
cout << "Astra sratatata" << endl << endl;
cout << "Powrot - 0" << endl << "Koniec - 1" << endl;
cout << "Podaj numer: ";
cin >> d3;
cout << endl << endl;
break;
case 2:
cout << "Omega sratatata" << endl << endl;
cout << "Powrot - 0" << endl << "Koniec - 0" << endl;
cout << "Podaj numer: ";
cin >> d3;
cout << endl << endl;
break;
default:
if (d2!=0)
{
cout << "Brak opcji: " << d2 << endl << endl;
}
else
{
cout << endl << endl;
}
break;
}
}
break;
default:
if (d!=0)
{
cout << "Brak opcji: " << d << endl << endl;
}
else
{
cout << "Nacisnij dowolny klawisz..." << endl;
}
break;
}
}
}