Czy ktoś może odpowiedzieć na pytanie dlaczego poniższy program odczytuje dane w sposób : np Kowalski Jan 23504204.5Lis 134.3Lis 4.5Lis?
Poprawne wyświetlenie np Kowalski Jan 23504 20 4.5 Lis Marzena 12345 13 4.3
zaznaczę ze program ma odczytać : nazwisko, imię, numer indeksu, wiek, średnia ocen 20 osob a juz przy 2 osobach robi takie jaja. Gdzie popełniłem błąd?
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <locale.h>
using namespace::std;
typedef struct
{
char nazwisko [10];
char imie [10];
char nr_albumu [5];
char wiek [2];
char srednia_ocen[3];
}
student;
student baza[100];
int ile_studentow=0, i=0;
char pobrany_znak;
void dodaj_studenta(student *baza)
{
do
{
printf("Nazwisko : ");
gets(baza[ile_studentow].nazwisko);
printf("Imie : ");
gets(baza[ile_studentow].imie);
printf("Nr albumu : ");
gets(baza[ile_studentow].nr_albumu);
printf("Wiek : ");
gets(baza[ile_studentow].wiek);
printf("Średnia ocen : ");
gets(baza[ile_studentow].srednia_ocen);
ile_studentow++;
}
while (ile_studentow<2);
}
int main ()
{
setlocale(LC_ALL,"Polish");
cout << "*** Baza danych studentów ***" << endl;
cout << endl;
cout << " Wprowadzanie danych :" << endl;
cout << endl;
FILE *fp;
dodaj_studenta(baza);
cout << ile_studentow << endl;
cout << baza[i].nazwisko << ' ';
cout << baza[i].imie << ' ';
cout << baza[i].nr_albumu << ' ';
cout << baza[i].wiek << ' ';
cout << baza[i].srednia_ocen;
cout << endl;
getch();
//---------------------------------------
return 0;
getch();
}
karolinaa