我在一个介绍性的C类,并有数据输入的问题。我正在对子程序进行练习,并且我的代码看起来是正确的,但程序中的一个问题由于某种原因被绕过,我无法弄清楚。scanf没有收取数据
1)所述的程序在ISBN书号为10个单独的字符(检查)
2)所述的程序在书(支票的价格读取)
3)所述的程序在读取读取学生的一类(检查)号
4)程序会询问天气的书是一个较新的版本或旧版本(不工作!)
5)该程序会询问天气书回覆需要或建议(支票)
我正在使用char对于新旧问题,以及所需或建议,因为我们假设dto为了利用我们迄今为止学到的东西。
我不明白为什么其中一个问题被绕过。
这里是我的输出:
Enter ISBN: 1231231231
Enter list price per copy: 54.99
Enter expected class enrollment: 45
Enter N for new edition or O for Older edition:
Enter R for Required or S for Suggested: R
ISBN: 1-23-123123-1
List Price: 54.99
Expected enrollment: 45
Edition, New or Old:
Importance, Required or Suggested: R
正如你可以看到,第四届问题scanf函数被忽略。 这是我迄今为止编写的代码。任何帮助是极大的赞赏。
谢谢。
#include <stdio.h>
#define WHOLESALE 80
void getInput(char* a, char* b, char* c, char* d, char* e,
char* f, char* g, char* h, char* i, char* j,
float* listPrice, int* numStudents, char* edition, char* importance);
void calc();
void calcBooks();
void calcProfit();
void output();
int main (void) {
// Local declarations
float listPrice;
int numStudents;
char edition;
char importance;
// ISBN char variables:
char a; // 1
char b; // 2
char c; // 3
char d; // 4
char e; // 5
char f; // 6
char g; // 7
char h; // 8
char i; // 9
char j; // 10
// Get input
getInput(&a, &b, &c, &d, &e, &f, &g, &h, &i, &j, &listPrice,
&numStudents, &edition, &importance);
// Calculate
// Output
printf("\nISBN: %c-%c%c-%c%c%c%c%c%c-%c\n", a, b, c, d, e, f, g, h, i, j); // ISBN output
printf("\nList Price: %6.2f", listPrice);
printf("\nExpected enrollment: %d", numStudents);
printf("\nEdition, New or Old: %c", edition);
printf("\nImportance, Required or Suggested: %c", importance);
return 0;
} // main
/* =============== getInput ==========================================
Gets input from the user.
Pre: addresses for ISBN (in seperate characters)
and for listPrice, numStudents, importance, and edition.
Post: Passes back values thru the addresses.
*/
void getInput(char* a, char* b, char* c, char* d, char* e,
char* f, char* g, char* h, char* i, char* j,
float* listPrice, int* numStudents, char* edition, char* importance)
{
printf("\nEnter ISBN: ");
scanf("%c%c%c%c%c%c%c%c%c%c", a,b,c,d,e,f,g,h,i,j);
printf("\nEnter list price per copy: ");
scanf("%f", listPrice);
printf("\nEnter expected class enrollment: ");
scanf("%d", numStudents);
printf("\nEnter N for new edition or O for Older edition: ");
scanf("%c", edition);
printf("\nEnter R for Required or S for Suggested: ");
scanf("%c", importance);
return;
} // getInput
'scanf'需要'&'存储字符! – haccks 2013-06-30 00:34:02