当多次调用同一函数时,是否可以为同一数据输入不同的值?

时间:2019-01-31 02:48:34

标签: c++

我正在用C ++创建一个学生数据管理程序,插入检查标记的功能有问题。

下面提供的代码足以重新创建程序的错误部分。

  • 我试图将sub[]的大小增加到16
  • 我试图一个接一个地插入数据而不是循环

以上似乎都无法解决问题

菜单功能:

char ch;
main_menu:
clrscr();
cout << "Press the key for your choice:\n";
cout << "D -> Edit details\n";
cout << "R -> Get result\n";
cout << "I -> Insert marks\n";
cout << "E -> Exit Program";

choice:
ch = getch();
switch(ch)
{
case 'd':   
    //edit_nam();           Ignore this one
    goto main_menu;
    break;

case 'i':
    ins_mar();
    goto main_menu;
    break;

case 'r':
    //get_res();           This one is not related to the problem
    goto main_menu;
    break;

case 'e':
    break;

default:
        goto choice;
}

插入标记功能:

for(int i = 0; i < 6; i++)
{
clrscr();
cout << "Enter details of subject:" << i + 1;
cout << "\nSubject name:";
cout << "\nMarks:";
gotoxy(14, 1);
cin.getline(student.marks[i].sub, 8);
gotoxy(7,2);
cin >> student.marks[i].mark;

(i != 5) ? cout << "\nPress any key to continue..." : cout << "\nPress any key to return to menu...";
getch();
}

学生结构:

struct stu
{
    char name[20];
int ID;
int cls;
mar marks[6];
};

标记结构:

struct mar
{
    char sub[8];
    float mark;
}

如果代码运行正常,则每次运行一次调用该功能时,都会要求用户输入所有六个主题的分数。

但是,事实并非如此。在第一次调用函数时,一切都以正确的方式进行,但是在其他任何一次运行中,它都不会在第一个主题之后询问主题名称。

0 个答案:

没有答案
相关问题