Hi guys, new to the forum so i hope that my first topic wont be full of errors.

Anyway, i just started programing a couple of weeks ago in a program at my elementary school, and i have a couple of Q's.

so this is my prog.

if(ima == true ){
                           for (i=0;i<N;i++){
              cout << polje[i].prezime << "   " << polje[i].ime << "   " << polje[i].identifikator<< "   " << polje[i].ocjena;
              cout << endl;
              }}
                   cout << "Broj diplomanata (N):";
                   cin >> N;
          for (i=0;i<N;i++){
          cout << "Identifikator:";
          cin >> polje[i].identifikator;
          cout << "Prezime:";
          cin.ignore();
          cin.getline(polje[i].prezime, 20);
          if (cin.gcount()==1)
          cin.getline(polje[i].prezime, 20);
          cout << "Ime:";
          cin.getline(polje[i].ime, 20);
          if (cin.gcount()==1)
          do{
          cout << "ocjena:";
          cin>>polje[i].ocjena;
          }while(polje[i].ocjena < 1 && polje[i].ocjena > 5);
          ima = true;

i want the program to be a structure like program so that i can enter ppls names, indicators, surnames and grades, but the problem is, i want the program to write out the names of the ppl i enter before, when i want to enter new names. which it does for the first time. For example, i enter 2 ppl, then i want to enter another one, and it writes out the 2 previous, but when i want to enter another one, it doesn't stack the first 2, and second 1, and it only writes out the second 1.

i hope you understand my question, my English is not very good, since I'm from Croatia.

also, could someone pls explain the orders, cin.ignore, cin.getline, and cin.gcount for me, since i dont quite understand them.


another problem is, it doesnt ask me for the ocjena, or in english, grades input.
thank you very much.

Recommended Answers

All 2 Replies

Maybe you can provide a sample input and resulting state/output?

okay here's a little example

#include <iostream.h>
struct people
{
char name[20];
int ID;
int Phone;
};
int main()
{
people ppl[10];
for (int i=0;i<10;i++)
{
cin.getline(ppl[i].name,20,'\n');
cin>>ppl[i].ID>>ppl[i].Phone;
}
return 0;
}

you can continue from here I guess

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.