Ir ao conteúdo
  • Cadastre-se

Valor da 'int main' não é puxado para o void de opção


HR BFH Gameplays
Ir à solução Resolvido por CiroboyBR,

Posts recomendados

GALERA!

o 'n' que é o numero de alunos não vem para as opções, assim quando declarado nos void ele pega valores aleatórios e acaba "estourando o for" até o compilador não responder!

alguem pode me ajudar?

AINDA TEM NA OPÇÃO 2 TEM QUE ORDENAR OS ALUNOS ATRAVES DE QUICKSORT PELA MATRICULA DE ORDEM CRESCENTE

 

MAS SE CONSEGUIR ME AJUDAR  NA 1ª OPÇÃO FICO MUITO GRATO! 

 

 

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <conio.h>

#define Max 60

 

struct ficha {

    char nome[30];

    int mat,idade;

    float nota;

};

 

void op1(struct ficha v[60]);

void op2(struct ficha v[60]);

void op3(struct ficha v[60]);

 

int main()

{

    struct ficha v[60];

    int n,x;

    printf("Informe a quantidade de alunos:\n");

    scanf("%i",&n);

    for(x=0;x<n;x++)

    {   printf("Informe o nome do %i aluno: \n ",x+1);

        fflush(stdin);

        gets(v[x].nome);

        printf("Insira a matricula do %i aluno: \n",x+1);

        scanf("%d",&v[x].idade);

        fflush(stdin);

        printf("Informe a idade do %i aluno: \n",x+1);

        fflush(stdin);

        scanf("%d",&v[x].mat);

        printf("Informe a nota do %i aluno: \n",x+1);

        fflush(stdin);

        scanf("%f",&v[x].nota);

        system ("cls");

    }

 

{

      char op;

      do{

        system("cls");

        printf("\n\n ==== MENU DE opções ====\n");

        printf("1-Listar as informações dos alunos: \n");

        printf("2-Organizar em ordem crescente (atraves da matricula): \n");

        printf("3-Pesquisa atraves da matricula: \n");

        printf("4-Sair: \n");

          op = getch();

          switch(op)

          {

               case '1':

                    system("cls");

                    printf("Opcao 1: \n");

                    op1 (v);

                    getch(); break;

               case '2':

                    system("cls");

                    printf("Opcao 2: \n");

                    op2 (v);

                    getch(); break;

               case '3':

                    system("cls");

                    printf("Opcao 3: \n");

                    op3 (v);

                    getch(); break;

 

               case '4': return 0;

               default: printf("Opcao invalida!\n");

          }

      }while(op != 0);

      getch();

      return 0;

}

    return 0;

}

 

 

 

void op1(struct ficha v[60])

{   int x,n;

    for(x=0;x<=n;x++)

    {printf("/n Nome do Aluno: %s",v[x].nome);

     printf("/n Idadde do Aluno: %d",v[x].idade);

     printf("/n Matricula do aluno: %d",v[x].mat);

     printf("/n Nota do Aluno: %2.2f",v[x].nota);

    }

 

 

 

}

Link para o comentário
Compartilhar em outros sites

  • Solução

passe o n como parâmetro na função

 

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>#define Max 60struct ficha {  char nome[30];  int mat,idade;  float nota;};void op1(struct ficha v[60], int n);void op2(struct ficha v[60] , int n);void op3(struct ficha v[60], int n);int main() {  struct ficha v[60];  int n,x;  printf("Informe a quantidade de alunos:\n");  scanf("%i",&n);  for(x=0; x<n; x++) {    printf("Informe o nome do %i aluno: \n ",x+1);    fflush(stdin);    gets(v[x].nome);    printf("Insira a matricula do %i aluno: \n",x+1);    scanf("%d",&v[x].idade);    fflush(stdin);    printf("Informe a idade do %i aluno: \n",x+1);    fflush(stdin);    scanf("%d",&v[x].mat);    printf("Informe a nota do %i aluno: \n",x+1);    fflush(stdin);    scanf("%f",&v[x].nota);    system ("cls");  }  {    char op;    do {      system("cls");      printf("\n\n ==== MENU DE opções ====\n");      printf("1-Listar as informações dos alunos: \n");      printf("2-Organizar em ordem crescente (atraves da matricula): \n");      printf("3-Pesquisa atraves da matricula: \n");      printf("4-Sair: \n");      op = getch();      switch(op) {      case '1':        system("cls");        printf("Opcao 1: \n");        op1 (v, n);        getch();        break;      case '2':        system("cls");        printf("Opcao 2: \n");        //op2 (v, n);        getch();        break;      case '3':        system("cls");        printf("Opcao 3: \n");        //op3 (v, n);        getch();        break;      case '4':        return 0;      default:        printf("Opcao invalida!\n");      }    } while(op != 0);    getch();    return 0;  }  return 0;}void op1(struct ficha v[60], int n) {  int x;  for(x=0; x<=n; x++) {    printf("/n Nome do Aluno: %s",v[x].nome);    printf("/n Idadde do Aluno: %d",v[x].idade);    printf("/n Matricula do aluno: %d",v[x].mat);    printf("/n Nota do Aluno: %2.2f",v[x].nota);  }}
Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...