שאלה
בחיה הראשונה הוא עושה מה שהוא צריך אבל בחיה השנייה הוא לא נותן לי להכניס את שם החיה. כלומר הוא כותב ":insert name of animal" אבל אז מיד קופץ שורה ועובר למספר הרגליים (כאילו לחצתי enter). למה?
בחיה הראשונה הוא עושה מה שהוא צריך אבל בחיה השנייה הוא לא נותן לי להכניס את שם החיה. כלומר הוא כותב ":insert name of animal" אבל אז מיד קופץ שורה ועובר למספר הרגליים (כאילו לחצתי enter). למה?
#include <iostream.h> struct animal_s { char name[30]; int legs; float tail_length; }; void set_animal(animal_s*); void show_animal(animal_s*); int main() { animal_s animal_1, animal_2; set_animal(&animal_1); set_animal(&animal_2); show_animal(&animal_1); show_animal(&animal_2); return 0; } void set_animal(animal_s *a) { cout<<"\ninsert name of animal: "; cin.getline( a->name, 30 ); cout<<"\ninsert number of legs: "; cin>>a->legs; cout<<"\ninsert length of tail: "; cin>>a->tail_length; } void show_animal(animal_s *b) { cout<<"\n\nThe animal: "<<b->name; cout<<"\nIt has "<<b->legs<<" legs, and its tail is "<<b->tail_length<<" ft long."; }