Siema,
własne przerabiam 'Szkołe programowania' Stephana Praty i napotkałem pewien problem.
Kod wygląda następująco:
#include <iostream>
#include "golf.h"
int decision = 1;
int main()
{
golf ann;
golf ebs[3];
int i = 0;
setgolf(ann, "Ann Sikora", 24);
while (setgolf(ebs[i]) && i < 3)
{
i++;
}
showgolf(ann);
for (int count = 0; count << i; count++)
{
showgolf(ebs[count]);
}
std::cout << std::endl;
std::cout << "Teraz mozesz zmienic wartosc hc!";
for (int count = 0; count << i; count++)
{
static int raw_data;
std::cout << "dla " << ebs[count].fullname << " :";
std::cin >> raw_data;
handicap(ebs[count], raw_data);
std::cout << std::endl;
}
for (int count = 0; count << i; count++)
{
showgolf(ebs[count]);
}
return 0;
}
#include <iostream>
#include "golf.h"
#include <cstring>
using std::cout;
using std::cin;
using std::endl;
void setgolf(golf& g, const char* name, int hc)
{
strncpy(g.fullname, name, Len);
g.handicap = hc;
}
int setgolf(golf& g)
{
char assist[Len];
cout << "Podaj pelne imie: ";
cin.getline(assist, Len);
if ((assist)[0] == '\0')
{
cin.clear();
return 0;
}
else
{
strcpy(g.fullname, assist);
cout << "Podaj hc: ";
cin >> g.handicap;
cin.get();
return 1;
}
}
void handicap(golf& g, int hc)
{
g.handicap = hc;
}
void showgolf(const golf& g)
{
cout << g.fullname << endl;
cout << g.handicap << endl;
}
PLIK NAGŁOWKOWY
#ifndef GOLF_H
#define GOLD_H
const int Len = 40;
struct golf
{
char fullname[Len];
int handicap;
};
void setgolf(golf& g, const char* name, int hc);
int setgolf(golf& g);
void handicap(golf& g, int hc);
void showgolf(const golf& g);
#endif
do mojej tablicy ebs wprowadzam dane, po zakonczeniu pojawia sie w konsoli jeszcze:
"Ann Sikora
24
Teraz mozesz zmienic wartosc hc!"
Po czym program konczy sie.
Ktoś ma moze pomysł dlaczego program jest przerywany w tym momencie?
Z góry dzięki za pomoc!