Program Egzamin na wskaźnikach

0

Witam wszystkich serdecznie, siedzimy z kolegą od 2h i robimy program. Przyznaje, opcje wskaźników nie idą nam najlepiej ale udało nam się naskrobać taki program. Jedyne co nam w nim nie działa jest to opcja do wpisywania ocen dla studentów. Jeśli jakaś dobra duszyczka poratuje nas radą to będziemy bardzo wdzięczni.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct student{
	char nazwisko[20];
	char imie[20];
	int indeks;
	float ocena;
	struct student* next;
}student;

int dlugosc_listy(student* student1)
{
    int d = 0;
    student* wsk = student1;
    while(wsk != NULL)
    {
              d++;
              wsk = wsk->next;
              }
    return d;
    }

void dodaj(student** student1, student* nowa){
	while (*student1 != NULL) student1 = &((*student1)->next);
     *student1 = nowa;
     nowa->next = NULL;
}

void dodajUcznia(student** student1){
		system("cls");
		student* nowa= (student*)malloc(sizeof(student));
			printf("Podaj Nazwisko:");
			scanf("%s",&nowa->nazwisko);
			
			printf("\nPodaj Imie:");
			scanf("%s",&nowa->imie);
	
			printf("\nPodaj Numer Indeksu:");
			scanf("%d",&nowa->indeks);
	
			nowa->ocena=0;
			
			system("cls");
			dodaj(student1,nowa);
}


void egzamin(student* student1){
	student* wsk = student1;
 
     if(student1 == NULL){
     printf("Brak studentow");
     getch();
 	 }
 	 float ocena=0;
     int i = 1;
     system("CLS");
     while( student1 != NULL)
     {
     		if(wsk->ocena==0){
            printf("Numer na liscie: %d \nImie: %s \nNazwisko: %s \nNumer albumu: %d\n", i, wsk->imie, wsk->nazwisko, wsk->indeks);
            printf("\nPodaj ocene ucznia: ");
            scanf("%f", ocena);
            ocena=wsk->ocena;
            wsk=wsk->next;
            i++;
        	}
        	else{
        	i++;
        	wsk=wsk->next;
			}
     }
     getch();
     system("CLS");
}

void usun(student** student1, int ID)
{
             student* poprzedni = NULL;
             student* wsk = *student1;
             int i;            
             for(i = 1; i < ID; i++)
             {
                     poprzedni=wsk;
                     wsk=wsk->next;
 
                     }
             if(poprzedni==NULL)
             {
             (*student1)=(*student1)->next;
             free(wsk);                               
             }
             else
             {
                 poprzedni->next=wsk->next;
                 free(wsk);
                 }
}
void rezygnacja(student** student1){
	 int ID;
     printf("Podaj numer osoby na liscie: " );
     scanf("%d", &ID);
 
     if((ID > dlugosc_listy(*student1)) || (ID < 1))
     {
           printf("Nie ma takiego numeru");
 
           }
     else
     {
         usun(student1,ID);         
         }
}


void lista_studentow(student* student1){

	student* wsk = student1;
 
     if(student1 == NULL){
     printf("Brak studentow");
     getch();
 	 }
     int i = 1;
     system("CLS");
     while( wsk != NULL)
     {
            printf("Numer na liscie: %d \nImie: %s \nNazwisko: %s \nNumer albumu: %d\n", i, wsk->imie, wsk->nazwisko, wsk->indeks);
            wsk=wsk->next;
            i++;
     }
     getch();
     system("CLS");
     
}

void przelicz_studentow(student* student1){
	
	student* wsk = student1;
 
     if(student1 == NULL){
     printf("Brak studentow");
     getch();
 	 }
     int i = 0;
     system("CLS");
     while( wsk != NULL)
     {
            wsk=wsk->next;
            i++;
     }
     printf("\nLista studentow zawiera: %d osob",i);
     getch();
     system("CLS");
}

void sredniaocen(student* student1){
	
	student* wsk = student1;
 
     if(student1 == NULL){
     printf("Brak studentow");
     getch();
 	 }
     system("CLS");
     float srednia=0;
     int i = 0;
     while( wsk != NULL || wsk->ocena != 0)
     {
     		if(wsk->ocena==0){
     			wsk=wsk->next;
			}
			else{
            srednia=srednia+wsk->ocena;
            wsk=wsk->next;
            i++;
        	}
     }
     printf("\nSrednia ocen uczniow wynosi: %d", srednia/i);
     getch();
     system("CLS");
	
}

int main(){

	student* student1 = NULL;
	
	
	int stop;
	
	while(stop!=9){
		printf("1. - Dodaj studenta");
		printf("\n2. - Rozpocznij egzamin");
		printf("\n3. - Rezygnacja studenta");
		printf("\n4. - Wyswietl liste studentow");
		printf("\n5. - Przelicz studentow");
		printf("\n6. - Srednia ocen egzaminu");
		printf("\n9. - Zakoncz program");
		printf("\nWybieram:");
		scanf("%d",&stop);
		
		switch(stop){
		//Dodaj studenta
		case 1:
			dodajUcznia(&student1);
			break;
		//Rozpocznij egzamin
		case 2:
			system("CLS");
			egzamin(student1);
			break;
		//Rezygnacja studenta
		case 3:
			rezygnacja(&student1);
			break;
		//Wyswietl liczbe studentow
		case 4:
			system("CLS");
			lista_studentow(student1);
			break;
		//Przelicz studentow 
		case 5:
			przelicz_studentow(student1);
			break;
		//Srednia ocen
		case 6:
			sredniaocen(&student1);
			break;
		}
	}
	system("cls");
	printf("Dziekuje za skorzystanie z programu, zegnam");
	getch();
	return 0;
}
0

@szweszwe: Zrobione, sorki ale myślałem, że samo to się zrobi. Nie do końca ogarnąłem

0

scanf("%s", &nowa->nazwisko); => scanf("%s", nowa->nazwisko);
while (student1 != NULL) { => while (wsk != NULL) {
scanf("%f", ocena); => scanf("%f", &ocena);
ocena = wsk->ocena; => wsk->ocena = ocena;
printf("\nSrednia ocen uczniow wynosi: %d", srednia / i); => printf("\nSrednia ocen uczniow wynosi: %f", srednia / i);
sredniaocen(&student1); => sredniaocen(student1);

while (wsk != NULL || wsk->ocena != 0) {
        if (wsk->ocena == 0) {
            wsk = wsk->next;
        }
        else {
            srednia = srednia + wsk->ocena;
            wsk = wsk->next;
            i++;
        }
    }

/

    while (wsk != NULL) {
        if (wsk->ocena != 0) {
            srednia = srednia + wsk->ocena;
            i++;
        }
        wsk = wsk->next;
    }

Czytajcie komunikaty kompilatora.

1 użytkowników online, w tym zalogowanych: 0, gości: 1