Witam,
Mam problem z kodem:
#include <iostream>
#include <string>
using namespace std;
int main()
{
struct uczen
{
string name;
int age;
float avg;
};
cout << "Podaj ilosc uczniow: ";
int ile;
cin >> ile;
uczen *ps = new uczen[ile];
for (int i = 0; i < ile; i++)
{
ps = ps + i;
cin >> ps->name;
//cin >> ps->age;
//cin >> ps->avg;
}
cout << "\nWyswietlam baze danych: \n";
ps = ps - ile + 1;
for (int j = 0; j < ile; j++)
{
ps = ps + j;
cout << ps->name << endl;
//cout << ps->age << endl;
//cout << ps->avg << endl << endl;
}
system("pause");
return 0;
}
W zależności od wartości ile, mam rożne zachowanie programu,przy 1 i 2 wszystko jest w porządku,
przy 3 i więcej mam coś takiego, oraz w konsoli CMD losowe znaki i liczby.
Czy ktoś potrafi zdiagnozować błąd?