Dev - C++ - Problema al imprimir datos de un registro

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

Problema al imprimir datos de un registro

Publicado por Pedro Manuel (2 intervenciones) el 18/09/2020 19:07:40
Buenos días, tardes o noches, me he encontrado con un problema en el cual no encuentro solución. Se trata de que al momento de imprimir los datos de una estructura salen de manera incorrecta, dejaré el código y la foto respectiva y si alguien me puede ayudar estaré agradecido:

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
#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <ctype.h>
#include <stdio.h>
#include <iomanip>
#include <time.h>
#include <string.h>
 
using namespace std;
 
void gotoxy(int x,int y)
{
	static HANDLE h = NULL;
	if(!h)
	h = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD c = { x,y };
	SetConsoleCursorPosition(h,c);
}
 
struct Corredor
{
	char Nombre[20];
	int edad;
	char Sexo[20];
	char Club[20];
};
 
int main()
{
 
	gotoxy(15,2);cout<<"* * * * * * * * * * * * * * * * * * * *";
	gotoxy(15,3);cout<<"CAPITULO II";
	gotoxy(15,4);cout<<"*=====================================*";
	gotoxy(15,5);cout<<"ESTRUCTURA DE DATOS";
	gotoxy(15,6);cout<<"*=====================================*";
	gotoxy(15,7);cout<<"TEMA";
	gotoxy(15,8);cout<<"*=====================================*";
	gotoxy(15,9);cout<<"REGISTROS (ESTRUCTURAS)";
	gotoxy(15,10);cout<<"*=====================================*";
	gotoxy(15,11),cout<<"EJEMPLO 01";
	gotoxy(15,12);cout<<"*=====================================*";
	gotoxy(15,13);cout<<"HACER UNA ESTRUCTURA, PEDIR DATOS AL";
	gotoxy(15,14);cout<<"USUARIO, IMPRIMIR TODOS LAS DATOS Y";
	gotoxy(15,15);cout<<"LA CATEGORIA DE LA COMPETICION.";
	gotoxy(15,16);cout<<"* * * * * * * * * * * * * * * * * * * *";
	gotoxy(1,20);cout<<"PRESIONE <ENTER> PARA CONTINUAR";
	getch();
	system("cls");
 
	int n;
	char categoria[20];
	Corredor c[n];
 
	cout<<"\nINGRESE EL NUMERO DE CONCURSANTES: ";cin>>n;
 
	for(int i=0; i<n; i++)
	{
		cout<<"\nCONCURSANTE NUMERO "<<i+1<<" :";
		fflush(stdin);
		cout<<"\nNOMBRE: "; cin.getline(c[i].Nombre,20,'\n');
		fflush(stdin);
		cout<<"\nEDAD: "; cin>>c[i].edad;
		fflush(stdin);
		cout<<"\nSEXO: "; cin.getline(c[i].Sexo,20,'\n');
		fflush(stdin);
		cout<<"\nCLUB: "; cin.getline(c[i].Club,20,'\n');
		fflush(stdin);
 
		if(c[i].edad <= 18)
		{
			strcpy(categoria,"Juvenil");
		}
		else if(c[i].edad <= 40 && c[i].edad >=19)
		{
			strcpy(categoria,"Senior");
		}
		else
		{
			strcpy(categoria,"Veterano");
		}
	}
 
	cout<<"\n\nMostrando Datos"<<endl;
	for(int i=0; i<n; i++)
	{
		fflush(stdin);
		cout<<"\nCONCURSANTE NUMERO "<<i+1<<" :"<<endl;
		cout<<"Nombre: "<<c[i].Nombre<<endl;
		fflush(stdin);
		cout<<"Edad: "<<c[i].edad<<endl;
		fflush(stdin);
		cout<<"Sexo: "<<c[i].Sexo<<endl;
		fflush(stdin);
		cout<<"Club: "<<c[i].Club<<endl;
		fflush(stdin);
		cout<<"Categoria: "<<categoria<<endl;
		cout<<"\n";
	}
 
	getch();
	return 0;
}
Captura-de-pantalla-26
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 Alfil
Val: 4.344
Oro
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Problema al imprimir datos de un registro

Publicado por Alfil (1444 intervenciones) el 18/09/2020 19:50:49
Te he corregido un poco algunas cosas que estaban mal, fíjate en las diferencias, también te he cambiado las librerías a librerías de c++ excepto string.h, que provocaría un cambio en el programa. Deberías plantearte cambiar la librería string.h por string (de c++), e incluir categoría en el struct.

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
#include <iostream>
#include <string.h>
#include <conio.h>
#include <windows.h>
 
using namespace std;
 
void gotoxy(int x,int y)
{
    static HANDLE h = NULL;
 
    if(!h)
        h = GetStdHandle(STD_OUTPUT_HANDLE);
 
    COORD c = { x,y };
    SetConsoleCursorPosition(h,c);
}
 
struct Corredor
{
    char Nombre[20];
    int edad;
    char Sexo[20];
    char Club[20];
};
 
int main()
{
    gotoxy(15,2);cout<<"* * * * * * * * * * * * * * * * * * * *";
    gotoxy(15,3);cout<<"CAPITULO II";
    gotoxy(15,4);cout<<"*=====================================*";
    gotoxy(15,5);cout<<"ESTRUCTURA DE DATOS";
    gotoxy(15,6);cout<<"*=====================================*";
    gotoxy(15,7);cout<<"TEMA";
    gotoxy(15,8);cout<<"*=====================================*";
    gotoxy(15,9);cout<<"REGISTROS (ESTRUCTURAS)";
    gotoxy(15,10);cout<<"*=====================================*";
    gotoxy(15,11),cout<<"EJEMPLO 01";
    gotoxy(15,12);cout<<"*=====================================*";
    gotoxy(15,13);cout<<"HACER UNA ESTRUCTURA, PEDIR DATOS AL";
    gotoxy(15,14);cout<<"USUARIO, IMPRIMIR TODOS LAS DATOS Y";
    gotoxy(15,15);cout<<"LA CATEGORIA DE LA COMPETICION.";
    gotoxy(15,16);cout<<"* * * * * * * * * * * * * * * * * * * *";
    gotoxy(1,20);cout<<"PRESIONE <ENTER> PARA CONTINUAR";
    getch();
    system("cls");
 
    int n;
    cout<<"\nINGRESE EL NUMERO DE CONCURSANTES: "; cin>>n;
    char categoria[20];
    Corredor c[n];
 
    for (int i = 0; i < n; i++)
    {
        cout<<"\nCONCURSANTE NUMERO " << i + 1 << ": ";
        fflush(stdin);
        cout << "\nNOMBRE: "; cin.getline(c[i].Nombre,20,'\n');
        fflush(stdin);
        cout << "\nEDAD: "; cin >> c[i].edad;
        fflush(stdin);
        cout << "\nSEXO: "; cin.getline(c[i].Sexo,20,'\n');
        fflush(stdin);
        cout << "\nCLUB: "; cin.getline(c[i].Club,20,'\n');
        fflush(stdin);
 
        if(c[i].edad <= 18)
        {
            strcpy(categoria,"Juvenil");
        }
        else if(c[i].edad <= 40 && c[i].edad >=19)
        {
            strcpy(categoria,"Senior");
        }
        else
        {
            strcpy(categoria,"Veterano");
        }
    }
 
    cout << "\n\nMostrando Datos" << endl;
    for(int i = 0; i < n; i++)
    {
        cout << "\nCONCURSANTE NUMERO " << i + 1 << ": " << endl;
        cout << "Nombre: " << c[i].Nombre << endl;
        cout << "Edad: " << c[i].edad << endl;
        cout << "Sexo: " << c[i].Sexo << endl;
        cout << "Club: " << c[i].Club << endl;
        cout << "Categoria: " << categoria << endl;
        cout << "\n";
    }
 
    getch();
 
    return 0;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil
Val: 6
Ha disminuido su posición en 3 puestos en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Problema al imprimir datos de un registro

Publicado por Pedro Manuel (2 intervenciones) el 19/09/2020 03:31:11
Lo acabo de revisar, gracias broo! <3
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