#include<iostream>
using namespace std;
const int SLEN = 30;
struct student
{
char fulname[SLEN];
char hobby[SLEN];
int ooplevel;
};
int getinfo(student pa[], int n);
void display1(student st);
void display2(const student * ps);
void display3(const student pa[], int n);
int main()
{
cout << "Podaj wielkosc grupy ";
int class_size;
cin >> class_size;
while(cin.get() != '\n')
continue;
student *ptr_stu = new student[class_size];
int entered = getinfo(ptr_stu, class_size);
for (int i = 0; i< entered; i++)
{
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
}
display3(ptr_stu, entered);
delete [] ptr_stu;
cout << "Gotowe!";
system("pause");
return 0;
}
int getinfo(student pa[], int n)
{
cout << "Rozpocznij wprowadzanie danych o studentach" << endl;
int i = 0;
for(i; i < n; i++)
{
cout << "Podaj imie studenta ";
char imie[SLEN];
cin >> imie;
#include<iostream>
using namespace std;
const int SLEN = 30;
struct student
{
char fulname[SLEN];
char hobby[SLEN];
int ooplevel;
};
int getinfo(student pa[], int n);
void display1(student st);
void display2(const student * ps);
void display3(const student pa[], int n);
int main()
{
cout << "Podaj wielkosc grupy ";
int class_size;
cin >> class_size;
while(cin.get() != '\n')
continue;
student *ptr_stu = new student[class_size];
int entered = getinfo(ptr_stu, class_size);
for (int i = 0; i< entered; i++)
{
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
}
display3(ptr_stu, entered);
delete [] ptr_stu;
cout << "Gotowe!";
system("pause");
return 0;
}
int getinfo(student pa[], int n)
{
cout << "Rozpocznij wprowadzanie danych o studentach" << endl;
int i = 0;
for(i; i < n; i++)
{
cout << "Podaj imie studenta ";
char imie[SLEN];
cin >> imie;
if(!cin)
{
cin.clear();
while (cin.get() != '\n') // ENTER konczy wprowadzanie"
continue;
cout << "bledne dane, wprowadzanie danych przerwane" << endl;
break;
}
else
{
strcpy(pa[i].fulname, imie);
cout << "Hobby: ";
cin >> pa[i].hobby;
cout << "Costam: ";
cin >> pa[i].ooplevel;
}
}
return i;
}
void display1(student st)
{
cout << "Student " << st.fulname << " hobby " << st.hobby << " costam " << st.ooplevel << endl;
}
void display2(const student * ps)
{
cout << "Student " << ps->fulname << " hobby " << ps->hobby << " costam " << ps->ooplevel << endl;
}
void display3(const student pa[], int n)
{
cout << "Wszyscy studenci";
for (int i = 0; i < n; i++)
{
cout << "Student " << i+1 << " " << pa[i].fulname << " hobby " << pa[i].hobby << " costam " << pa[i].ooplevel << endl;
};
}
{
strcpy(pa[i].fulname, imie);
cout << "Hobby: ";
cin >> pa[i].hobby;
cout << "Costam: ";
cin >> pa[i].ooplevel;
}
}
return i;
}
void display1(student st)
{
cout << "Student " << st.fulname << " hobby " << st.hobby << " costam " << st.ooplevel << endl;
}
void display2(const student * ps)
{
cout << "Student " << ps->fulname << " hobby " << ps->hobby << " costam " << ps->ooplevel << endl;
}
void display3(const student pa[], int n)
{
cout << "Wszyscy studenci";
for (int i = 0; i < n; i++)
{
cout << "Student " << i+1 << " " << pa[i].fulname << " hobby " << pa[i].hobby << " costam " << pa[i].ooplevel << endl;
};
}
Witam wszystkich, miałem długą przerwę w c++ z racji sesji, ale powoli wracam do nauki.
Mam problem z instrukcją break w petli:
if(!cin)
{
cin.clear();
while (cin.get() != '\n') // ENTER konczy wprowadzanie"
continue;
cout << "bledne dane, wprowadzanie danych przerwane" << endl;
break;
}
else
{
strcpy(pa[i].fulname, imie);
cout << "Hobby: ";
cin >> pa[i].hobby;
cout << "Costam: ";
cin >> pa[i].ooplevel;
}
}
Chciałbym, żeby wprowadzenie ENTER przerwało pętlę.
Pozdrawiam