28-10-2009, 20:37
|
|
|
|
חבר מתאריך: 04.11.04
הודעות: 6,986
|
|
שאלה של מתחיל ב-c - קליטת משתנה char
הבעיה שלי היא בקטע המודגש - אחרי שהתכנית נכסנת ללולאה (והיא נכנסת, selection מקבל n בתחילת התכנית), במקום לעצור ב-scanf לקלוט אות מהמשתמש, היא מדלגת על השורה הזאת וישר עוברת ל-if וכמובן שחוזרת שוב לתחילת הלולאה, ורק אז היא נעצרת לקבל אות.
מה אני מפספס פה?
קוד:
printf ("How many students will participate in the survey?\n");
scanf ("%d",&student_number);
for (survey_counter=1; survey_counter<=student_number;survey_counter++){
printf ("Student %d :\n",survey_counter);
while ((selection!='m')&&(selection!='e'))
{
printf ("1)Do you study in the morning (m) or in the evening (e)?\n");
scanf ("%c",&selection);
if ((selection!='m')&&(selection!='e')){
printf ("Incorrect letter!! Please select (m) for morning and (e) for evening\n");
}
}
if (selection=='m') {
morning++;
}
else evening++;
printf ("2)Do you study alone (a) or with a group (g)?\n");
printf ("3)Do you study with music (m) or prefer silence (s)?\n");
}
|