Dev - C++ - Ayuda con un login y menu en c++

 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado su posición en 3 puestos en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Ayuda con un login y menu en c++

Publicado por Luis (1 intervención) el 18/01/2020 00:40:27
Hola, necesito ayuda con un tema lo que sucede es que, luego de fallar 3 veces en el login de todas formas entra en mi menu . como puedo hacer para que cuando falle al ingresar las tres veces . no acceda a mi menu !
les dejo el codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<fstream>
//EXTENCION
#define EXT 30
//AQUI SE DEFINE USUARIO Y CLAVE
#define USER "proyecto"
#define PASS "bancodesangre"
#define ENTER 13
#define BACKSPACE 8
 
using namespace std;
string Login();
 
void escribir();
void archivos();
void editar();
void salir();
void menu();
 
//ESTRUCTUTA ANIDADA
struct gruposangre{
	string tipodesangre;
};
struct registro{
	string nombre;
	int edad;
	string direc;
	int telef;
	struct gruposangre tipo;
	int pintas;
}persona[EXT];
 
int main(){
 int op,n;
 
 string usuario,password;
 // SE INICIA UN CONTADOR EN 0, MAS TARDE SERVIRA PARA DEFINIR EL MAXIMO DE INTENTOS PARA ENTRAR AL SISTEMA
  int contador = 0;
 //HACEMOS USO DE BOOL PARA USAR EL VOF EN UN IF QUE SERVIRA PARA DTERMINAR LA VALIDACION
  bool ingresa = false;
 
  //AQUI SOLO SE EMPIESA A DEARROLLAR EL MENU DE LOGIN
  do{
    //system("cls");
        cout<<"\t\t\tLOGIN DE USUARIO"<<endl;
        cout<<"\t\t\t----------------"<<endl;
        cout<<"\n\t\ Usuario: ";
        getline(cin, usuario);
 
        char caracter;
 
        cout << "\tPassword: ";
        caracter = getch();
 
    password="";
    //HACEMOS USO DE LOS CODIGOS ASKI PARA REEMPLAZAR CARACTERES
    while(caracter!=13){
 
        if(caracter!=8){
            password.push_back(caracter);
            cout<<"*";
 
        }else{
           if(password.length()> 0){
            //SE IMPRIME UN CARACTER EN LA PANTALLA, PERMITE BORRAR UN CARACTER DEL ESPACIOY VUELVE A UBICARSE EN LA POSICION BORRADA
           cout<<"\b \b";
           //PERMITE BORRAR UN CARACTER MENOS EL ULTIMO
           password=password.substr(0, password.length() -1);
           }
        }
        caracter=getch();
    }
        /* DECIMOS QUE USUARIO Y PASSWORD DEBEN SER IGUALES A LOS DEFINIDOS AL INICIO DESDE LA LINEA  85 A LA 98 LO QUE SE REALIZA
        ES VERDIFICAR LOS VALORES DE BOOL VOF QUE CONCUERDE LO QUE EL USARIO INGRESA TAMBIEN EL CONTADOR SE PONE EN USO DELIMITADO LAS VECES QUE SE PUEDE
        REALIZAR ESTA ACCION HASTA 3 INTENTOS */
        if (usuario== USER && password== PASS){
            ingresa = true;
        }else {
             cout<<"\n\n\tEL usuario y/o password son incorrectos"<<endl;
             cin.get();
             contador++;
     system("cls");
 
        }
  }while(ingresa == false && contador < 3);
 
  if (ingresa == false){
    cout<<"\n\tUsted no pudo ingresar al sistema. vays"<<endl;
  }else{
    cout<<"\n\tBienvenido al sistema"<<endl;
  }
 
  cin.get();
 
    system("cls");
 
    menu();
    abort();
    system("PAUSE");
}
 
void menu(){
     int op=0;
 
    //system("cls");
 do{
    cout<<"\t\t\t***BANCO DE SANGRE***"<<endl;
    cout<<"\t\t\t        MENU"<<endl;
    cout<<"\t\t\t 1. REGISTRAR DONANTE"<<endl;
    cout<<"\t\t\t 2. VISUALIZAR ARCHIVOS"<<endl;
    cout<<"\t\t\t 3. EDITAR ARCHIVOS"<<endl;
    cout<<"\t\t\t 4. SALIR"<<endl;
    cout<<"\t\t\t INGRESE LA OPCION"<<endl;
    cin>>op;
    system("cls");
 
  switch(op){
 
      case 1:
            escribir();//SE LLAMA LA FUNCION
      break;
 
      case 2:
            cout<<"\t\t\tVisualizar Archivos"<<endl;
            archivos();//SE LLAMA LA FUNCION
      break;
 
      case 3:
            //editar();//SE LLAMA LA FUNCION
      break;
 
      case 4:
            //salir();//SE LLAMA LA FUNCION
      break;
      default:
        cout<<"LA OPCION QUE INGRESO NO EXISTE "<<endl; }
 
       }while(op!=4);
}
 
void escribir(){
    int n,op2;
    ofstream archivo;
    archivo.open("Pintas.txt",ios::out|ios::app);//ABRIR EL ARCHIVO PARA INCLUIR TEXTO
 
    if(archivo.fail()){
        cout<<"\t\t\tNO SE PUDO ABRIR EL ARCHIVO";
 
    }
    cout<<"\t\t\tCuantos Donantes Desea Registrar:";
    cin>>n;
    for (int i=0;i<n;i++){
        fflush(stdin);//BACIAR EL BUFFER Y PERMITIR DIGITAR VALORES
 
        cout<<"\t\t\tDATOS DEL DONANTE"<<endl;
 
        cout<<"\t\t\tNombre: "<<endl;
        getline(cin,persona[i].nombre);
 
        cout<<"\t\t\tEdad: "<<endl;
        cin>>persona[i].edad;
 
        fflush(stdin);
 
        cout<<"\t\t\tDireccion: "<<endl;
        getline(cin,persona[i].direc);
 
        cout<<"\t\t\tTelefono: "<<endl;
        cin>>persona[i].telef;
 
        fflush(stdin);
 
        cout<<"\t\t\tTipo de Sangre: "<<endl;
        getline(cin,persona[i].tipo.tipodesangre);
 
        fflush(stdin);
 
        cout<<"\t\t\tNumero de pintas a donar: "<<endl;
        cin>>persona[i].pintas;
 
        cout<<"Pulse 1 Para Guardar Este Registro ";
        cin>>op2;
        if(op2 == 1)
        {
            archivo<<"Nombre: "<<persona[i].nombre<<endl;
            archivo<<"Edad: "<<persona[i].edad<<endl;
            archivo<<"Direccion: "<<persona[i].direc<<endl;
            archivo<<"Telefono: "<<persona[i].telef<<endl;
            archivo<<"Tipo de Sangre: "<<persona[i].tipo.tipodesangre<<endl;
            archivo<<"Numero de pintas a Donar: "<<persona[i].pintas<<endl;
 
        //SYSTEM (CLS);
        cout<<"REGISTRO GUARDADO"<<endl;
        cout<<"PULSE ENTER PARA CONTINUAR"<<endl;
        system("pause");
        system("cls");
        }
 
        archivo.close();
    }
}
void archivos(){
 
    ifstream archivo;
    string texto;
    archivo.open("Pintas.txt");//ABRIR EL ARCHIVO PARA VER EN PANTALLA
 
    if(archivo.fail()){
        cout<<"\t\t\tNO SE PUDO ABRIR EL ARCHIVO";
        exit(1);
    }
    	while(!archivo.eof()){ //MIENTRAS NO SEA EL FINAL DE ARCHIVO
 
		getline(archivo,texto);
		cout<<texto<<endl;
	}
 
    fflush(stdin);//BACIAR EL BUFFER Y PERMITIR DIGITAR VALORES
    archivo.close();
 
    cout<<"Pulse enter para Continuar ";
 
    system("pause");
    system("cls");
 
    }
 
void editar(){
 
 
}
 
void salir(){
    cout<<"Programa Finalizado"<<endl;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Rodrigo
Val: 1.755
Plata
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Ayuda con un login y menu en c++

Publicado por Rodrigo (539 intervenciones) el 18/01/2020 17:30:13
Tienes la invocacion de menu() incondicional, ponla en el else del if() anterior, justo despues del cout "Bienvenido .."
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar