Mam taki problem, że chciałem napisać program któremu podajesz ilość osób i ich imiona i nr telefonu. Mam taki kod:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
int nr = 0;
string Nazwy[10];
long TelNr[10];
int IloscOsob;
cout << "Podaj ilosc osob:" << endl;
cin >> IloscOsob;
if (IloscOsob < 1)
{
cout << "Za malo osob." << endl;
system("pause");
return 0;
}
if (IloscOsob > 10)
{
cout << "Nie za duzo?" << endl;
system("pause");
return 0;
}
for (int nr = 0; nr != IloscOsob; nr++)
{
cout << "\nOsoba " << nr+1 << ":" << endl;
cin >> Nazwy[10];
cout << "Nr telefonu:" << endl;
cin >> TelNr[10];
}
ofstream Dane
("dane.txt", ios::app);
for (int b = 0; b != IloscOsob; b++)
{
Dane << "\nOsoba " << nr+1 << ":" << Nazwy[10] << " Telefon:" << TelNr[10] << endl;
cout << "\nOsoba " << nr+1 << ":" << Nazwy[10] << " Telefon:" << TelNr[10] << endl;
}
system("pause");
Dane.close();
return 0;
}
Niby działa, ale jak wpisze imię to wywala program. ;/
Problem chyba jest w tym
string Nazwy[10];
Dane << "\nOsoba " << nr+1 << ":" << Nazwy[10] << " Telefon:" << TelNr[10] << endl;
cout << "\nOsoba " << nr+1 << ":" << Nazwy[10] << " Telefon:" << TelNr[10] << endl;
Ale dokładnie nie wiem, weźcie coś poradźcie! xD