swith into while

Hello, you knows why is happenig this. I mean, when I run the code and introduce a mistake the default in the switch supposed to capture the mistakeand restart the loop(while). Instead cmd shows somthing like: (I mean runs without any control)


Bienvenido
Seleccione una opci¾n
1. Capturar Equipos
2. Registrar Marcadores
3. Ver EstadÝsticas
4. Reglas de la Quiniela
5. Salir

cgfyjfgyh
No selecciono un valor vßlido
Seleccione una opci¾n
1. Capturar Equipos
2. Registrar Marcadores
3. Ver EstadÝsticas
4. Reglas de la Quiniela
5. Salir
No selecciono un valor vßlido
Seleccione una opci¾n

1. Capturar Equipos
2. Registrar Marcadores
3. Ver EstadÝsticas
4. Reglas de la Quiniela
5. Salir
No selecciono un valor vßlido
Seleccione una opci¾n
1. Capturar Equipos
2. Registrar Marcadores
3. Ver EstadÝsticas
4. Reglas de la Quiniela

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
  #include <iostream>
#include <cctype>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using namespace std;

void Menu();
int main()
{
   cout<<"\nBienvenido\n"<<endl;

   Menu();
    return 0;
}

void Menu(){
    int eleccion;
    while(eleccion!=5){

            cout<<"Seleccione una opción\n"<<endl;
            cout<<"1. Capturar Equipos"<<endl;
            cout<<"2. Registrar Marcadores"<<endl;
            cout<<"3. Ver Estadísticas"<<endl;
            cout<<"4. Reglas de la Quiniela\n\n"<<endl;
            cout<<"5. Salir"<<endl;
            cin>>eleccion;

                switch((eleccion)){
                    case 1:    cout<<"Eligio 1"<<endl;
                        system("cls");
                        break;
                    case 2:   cout<<"Eligio 2"<<endl;
                        system("cls");
                        break;
                    case 3:  cout<<"Eligio 3"<<endl;
                        break;
                    case 4:  cout<<"Eligio 4"<<endl;
                        system("cls");
                        break;
                    case 5: cout<<"Eligio 5"<<endl;
                        system("cls");
                        cout<<"Gracias"<<endl;
                        break;
                    default:cout<<"No selecciono un valor válido"<<endl;
                       // return;
                        break;
                 }
            }
}


you compiler settings are unable to handle the non-english characters you are using for some of the words.

see how the issue is on the accented n in opción or the i in Estadísticas ?
that is your issue. I am not sure what you need to change for it, but your CODE is fine, this is a setting.
it could ALSO be that the TEXT in the CODE is wrong, coming from something like MSWORD, and you need to retype it using a simple editor. Some special letters are replaced with 'better looking' versions by the text editor, but which is not compatible with CODE (without using unicode or the like, that is).

what do you get if you do this:
cout << (char)(162) << endl;

Last edited on
Topic archived. No new replies allowed.