C++学生数据库管理系统输入随机跳过问题求助
学生数据库管理系统输入步骤跳过问题
我正在开发一款学生数据库管理系统,测试添加新学生功能时,程序会随机跳过输入步骤,直接进入下一项,无法输入被跳过的内容。例如输入完姓名后,显示“请输入所学专业(Programme of study)”的提示后,会立即在同一行出现“请输入学习等级(C、I或H)”的提示,根本没法输入专业信息。
相关代码
int main() { // 设置输入姓名的最大长度为20 char data[20]; int n = 0, option = 0, nCount = 0; // 初始化科目成绩 string empty = "00"; string programme = " "; string department = " "; char level = ' '; // 存储数据库的文件名 ifstream f("SDB.txt"); string line; // 统计文件中的总行数 for (int i = 0; std::getline(f, line); ++i) { nCount++; } // 选项页面 while (option != 5) { cout << "\nPlease choose an option\n" "1. Add new students\n" "2. Student Login\n" "3. Staff Login\n" "4. Admin View\n" "5. Exit\n" "Enter option: "; cin >> option; // 选择不同选项后的操作 if (option == 1) { cout << "Enter the number of students: "; cin >> n; nCount = nCount + n; for (int i = 0; i < n; i++) { ofstream outfile; outfile.open("SDB.txt", ios::app); // 存储学生的完整数据 cout << "Please enter your student ID number: "; cin >> data; outfile << data << "\t"; cout << "Please enter your name: "; cin >> data; int len = strlen(data); // 检查输入姓名的长度 while (len < 20) { data[len] = ' '; len = len + 1; } outfile << data << "\n"; // 录入所学专业 cout << "Please enter the Programme of study you are in: "; cin >> programme; outfile << programme << "\t"; // 录入学习等级 cout << "Please enter which level of study you are in(C, I or H): "; cin >> level; outfile << level << "\t"; // 初始插入空成绩数据 outfile << empty << "\t"; outfile << empty << "\t"; outfile << empty << "\t"; outfile << empty << "\t"; cout << "\nPlease enter which department you are in: "; cin >> department; outfile << department << endl; } } } }
内容的提问来源于stack exchange,提问作者LGGawd
相关产品推荐
相关产品推荐

