Ir para conteúdo
Fórum Script Brasil
  • 0

Media de Aluno com ponteiro


Rafael.s

Pergunta

eu tenho isso em maos e não sei de onde e para onde partir, tenho que percorrer a lista e sair o nome e a media final dos alunos

#include <stdio.h>
#define true 1

struct prs{
       char nome[30];
       float n1,n2,n3,n4,media;       
       struct prs *ptrprox;
       };
       struct prs *ptrprim, *ptratual, *ptrnovo;
       main(){
              char ch;                   
              ptrprim=(struct prs*)NULL;
              while (true){
                    printf ("\nDigite 'e' para inserir");
                    printf ("\nDigte 'l' para a lista");
                    printf ("\n");
                    ch=getche();
                           switch (ch){
                           case 'e':novonome(); break;
                           case 'l':listatudo(); break;
                           defaut: ("\n Digite opções validas");
                           }
                           }
                           } 
                           novonome(){
                                ptrnovo=(struct prs*) malloc(sizeof(struct prs));
                                if (ptrprim==(struct prs*)NULL){
                                                     ptrprim=ptrnovo;
                                                     ptratual=ptrnovo;
                                                     }else{
                                                           ptratual=ptrprim;
                                                           while(ptratual->ptrprox!=(struct prs*)NULL){
                                                                  ptratual=ptratual->ptrprox;
                                                                  }
                                                                  ptratual->ptrprox=ptrnovo;
                                                                  ptratual=ptrnovo;
                                                                  }
                                                                  printf ("\n Digite o nome ");                                                                  
                                                                  gets (ptratual->nome);
                                                                  ptratual->ptrprox=(struct prs*)NULL;
                                                                  printf ("\n Digite a primeira nota\n"); 
                                                                  gets (ptratual->nome);
                                                                  ptratual->ptrprox=(struct prs*)NULL;   
                                                                  printf ("\n Digite a segunda nota\n"); 
                                                                  gets (ptratual->nome);
                                                                  ptratual->ptrprox=(struct prs*)NULL;
                                                                  printf ("\n Digite a terceira nota\n"); 
                                                                  gets (ptratual->nome);
                                                                  ptratual->ptrprox=(struct prs*)NULL;
                                                                  printf ("\n Digite a quarta nota\n");                                                              
                                                                  gets (ptratual->nome);
                                                                  ptratual->ptrprox=(struct prs*)NULL;
                                                                  (*ptratual).media=((*ptratual).n1+(*ptratual).n2+(*ptratual).n3+(*ptratual).n4)/4;
                                                                  if((*ptratual).media>=6)
                                                                  printf("Aprovado");
                                                                  else{
                                                                       printf("Aluno reprovado");
                                                                       }
                                                                  }
                                                                  listatudo(){
                                                                       if(ptrprim==(struct prs*)NULL){
                                                                       printf ("\n lista vazia \n");
                                                                       (*ptratual).media=((*ptratual).n1+(*ptratual).n2+(*ptratual).n3+(*ptratual).n4)/4;
                                                                       if((*ptratual).media>=6)
                                                                       printf("Aprovado");
                                                                       else{
                                                                       printf("Aluno reprovado");
                                                                       }
                                                                       return;
                                                                       }
                                                                       ptratual=ptrprim;
                                                                       do{
                                                                          printf ("\n nome%s\n", ptratual->nome);
                                                                          ptratual=ptratual->ptrprox;                                                               
                                                                          //printf ("\n Media %f\n", ptratual->media);
                                                                         // ptratual=ptratual->ptrprox;
                                                                          }while (ptratual!=(struct prs*)NULL);
                                                                          }

Grato desde já quem puder ajudar.

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,4k
×
×
  • Criar Novo...