Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

menu w programie-nie cofa do poprzedniej sekcji

Ostatnio zmodyfikowano 2017-01-09 12:16
Autor Wiadomość
Kaleh
Temat założony przez niniejszego użytkownika
menu w programie-nie cofa do poprzedniej sekcji
» 2017-01-07 21:08:55
Piszę prosty program, w którym będę umieszczał moje postępy z c++.
Stworzyłem podstawy do menu, ale nie działa cofanie z void zegar() do void menu().
Załączam treść programu:

C/C++
#include <iostream>
#include <windows.h>
#include <cstdlib>

using namespace std;

int stoperstart;
int zegartype;
int menutype;

void stoper()
{
    int stoper;
    while(( stoperstart != 0 && stoperstart != 1 ) ||( zegartype == 1 ) )
    {
        system( "cls" );
        cout << "Ostrzezenie!" << endl;
        cout << "Gdy program ruszy, nie da sie go zatrzymac (chyba ze poprzez wylaczenie go)." << endl;
        cout << "Program sam zatrzyma sie, gdy liczba wyjdzie poza zakres zmiennej int, lecz nie bedzie mozna wedy z niego korzystac." << endl;
        cout << "0.Powrot" << endl;
        cout << "1.Start" << endl;
        cin >> stoperstart;
        if( stoperstart == 1 )
        {
            for( int stoper = 0; stoper >= 0; stoper++ )
            {
                system( "cls" );
                cout << stoper << " sekund od uruchomienia" << endl;
                Sleep( 1000 );
            }
        }
    }
}

void zegar()
{
    if( stoperstart == 0 ) ||( zegartype != 0 && zegartype != 1 ) ||( menutype == 1 )
    {
        system( "cls" );
        cout << "0.Wstecz" << endl;
        cout << "1.Stoper" << endl;
        cin >> zegartype;
        if( zegartype == 1 )
        {
            stoper();
        }
    }
}

void menu()
{
    do
    {
        system( "cls" );
        cout << "0.Wyjdz" << endl;
        cout << "1.Zegar" << endl;
        cin >> menutype;
        switch( menutype )
        {
        case 1:
            zegar();
            break;
        }
    } while(( zegartype == 0 ) ||( menutype != 0 && menutype != 1 ) );
   
}

int main()
{
    string imie;
    int haslo;
   
    cout << "Jak sie nazywasz?" << endl;
    cin >> imie;
    system( "cls" );
    cout << "Witaj " << imie << ", prosze podac haslo:";
    cin >> haslo;
    if( haslo == 123 )
    {
        menu();
    }
    else
    {
        cout << "Haslo nieprawidlowe; program wylaczy sie za:" << endl;
        int zle;
        for( int zle = 3; zle >= 0; zle-- )
        {
            Sleep( 1000 );
            system( "cls" );
            cout << zle << endl;
        }
        cout << "koniec." << endl;
    }
    return 0;
}
P-156187
darko202
» 2017-01-09 12:16:19
1.
technika debugowania - szybko poznaj

2.
&& to operator i
( stoperstart != 0 && stoperstart != 1 ) zawsze zwraca false  // po co więc jest

C/C++
void stoper()
{
    ...
    while(( stoperstart != 0 && stoperstart != 1 ) ||( zegartype == 1 ) ) // to zależy więc od zegartype
    {
        ...// a tu nie jest zmieniane
       
    }
}

pewnie dlatego nie może opuścić tej pętli
podobnie konstrukcje w innych funkcjach

 
P-156235
« 1 »
  Strona 1 z 1