edit: problemy tutaj zostały rozwiązane, jeszcze jeden post z pytaniem dodałem i dlatego temat "odkopany" ;)
Witam,
mam problem z zadankiem. Ogólnie do podanego pliku nagłówkowego miałem utworzyć funkcje oraz zawrzeć je w main(), jednak z jakiegoś względu mimo poprawnej kompilacji program nie działa jak należy. Mógłbym prosić o spojrzenie co może być nie tak? Z góry dziękuję za pomoc!
Plik nagłówkowy golf.h
#ifndef GOLF_H_
#define GOLF_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
Plik z funkcjami golf.cpp
#include "golf.h"
#include <iostream>
#include <cstring>
using namespace std;
void setgolf(golf & g, const char * name, int hc)
{
strcpy(g.fullname, name);
g.handicap = hc;
}
int setgolf(golf & g)
{
cout << "Podaj imie: ";
cin.get(g.fullname, len);
if ((g.fullname)[0] == '\0')
{
cin.clear();
return 0;
}
else
{
cout << "Podaj handicap: ";
cin >> g.handicap;
return 1;
}
}
void handicap(golf & g, int hc)
{
g.handicap = hc;
}
void showgolf(const golf & g)
{
cout << "Imie: " << g.fullname << endl;
cout << "Handicap: " << g.handicap << endl;
}
main.cpp
#include <iostream>
#include "golf.h"
#include <ctype.h>
using namespace std;
int main()
{
cout << "Ilu golfistow chcesz dodac: ";
int golfisci;
cin >> golfisci;
const char miszcz[7] = "Mistrz";
golf zaw[golfisci];
int wprowadzeni = 0;
for (int i = 0; i < golfisci; i++)
{
if (i == 0)
{
setgolf(zaw[i], miszcz, 10);
wprowadzeni++;
}
else
{
setgolf(zaw[i]);
if ((zaw[i].fullname)[0] == '/0')
break;
wprowadzeni++;
}
}
cout << "Pokazuje wszystkich zawodnikow: " << endl;
for (int i = 0; i < wprowadzeni; i++)
{
cout << "Zawodnik " << i << ":" << endl;
showgolf(zaw[i]);
cout << endl;
}
cout << "Czy chcesz zmienic handicap zawodnika?(T/N): ";
char odp[1];
cin.get(odp, 1);
toupper(odp[0]);
while (odp[0] != 'N')
{
if (odp[0] == 'T')
{
cout << "Podaj numer zawodnika do zmiany: ";
int num;
cin >> num;
while (num > wprowadzeni || num < 0)
{
cout << "Nie ma takiego zawodnika, wybierz poprawny numer: ";
cin.clear();
cin >> num;
}
cout << "Podaj handicap: ";
int handi;
cin >> handi;
handicap(zaw[num], handi);
"Czy chcesz zmienic handicap kolejnego zawodnika?(T/N): ";
cin.get(odp, 1);
toupper(odp[0]);
}
else
{
cout << "Bledny wybor, sprobuj ponownie: ";
cin.get(odp, 1);
toupper(odp[0]);
}
};
return 0;
}