gpt4 book ai didi

C++ 一个一个地传递一个结构数组——如此简单,但我被难住了

转载 作者:搜寻专家 更新时间:2023-10-31 00:03:37 25 4
gpt4 key购买 nike

<分区>

首先非常感谢所有提供帮助的人!

我试图在这里一次传递一个变量,而不是整个数组。我知道我很接近,但我已经搜索了又搜索,但找不到我做错了什么。

我收到的错误是

void PrintRecords(studentRec& myRec)

它说:“PrintRecords”字段的变量声明为无效

#include <iostream>
using namespace std;

struct studenRec {
string name;
string address;
string city;
string state;
string zip;
char gender;
string myid;
float gpa;
};

void PrintRecords(studenRec& myRec);

int main()
{
studenRec myRec[3];

for (int i = 0; i < 3; i++) {
cout << "Students name: ";
getline(cin, myRec[i].name);
cout << "Students address: ";
getline(cin, myRec[i].address);
cout << "Students city: ";
getline(cin, myRec[i].city);
cout << "Students state: ";
getline(cin, myRec[i].state);
cout << "Students zip: ";
getline(cin, myRec[i].zip);
cout << "Students gender: ";
cin >> myRec[i].gender;
cin.ignore(1000,10);
cout << "Students id: ";
getline(cin, myRec[i].myid);
cout << "Students gpa: ";
cin >> myRec[i].gpa;
cin.ignore(1000,10);
cout << "STUDENT RECORDED SUCCESSFULLY" << endl;
cout << endl;
}

cout << "-------------------------------" << endl;

for (int i = 0; i < 3; i++) {
PrintRecords(myRec[i]);
}

return 0;
} // main

void PrintRecords(studentRec& myRec)
{
cout << "Students name: " << myRec.name << endl;
cout << "Students address: " << myRec.address << endl;
cout << "Students city: " << myRec.city << endl;
cout << "Students state: " << myRec.state << endl;
cout << "Students zip: " << myRec.zip << endl;
cout << "Students gender: " << myRec.gender << endl;
cout << "Students id: " << myRec.myid << endl;
cout << "Students gpa: " << myRec.gpa << endl;
cout << endl;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com