하십시오,이 코드이 코드를 수정하는 방법
를 해결하는 방법[Error] a function-definition is not allowed here before '}' token
[Error] expected '}' at the end of input
내가 이미 컴파일러 오류
#include<iostream>
using namespace std;
struct name_type
{
string first,middle,last;
};
struct SD
{
name_type name;
float grade;
};
const int MAX_SIZE = 35;
int isFull(int last) {
if(last == MAX_SIZE - 1) {
return(1);
}
else {
return(0);
}
}
int isEmpty(int last) {
if(last < 0) {
return(1);
}
else {
return(0);
}
}
main()
{
SD SD2[MAX_SIZE];
int last = -1;
if(isEmpty(last))
{
cout << "List is empty\n";
}
for (int a=0; a <35; a++)
{
cout << "Enter first name:.....";
cin >> SD2[a].name.first;
cout << "Enter middle name:....";
cin >> SD2[a].name.middle;
cout << "Enter last name:......";
cin >> SD2[a].name.last;
cout << "Enter your grade:.....";
cin >> SD2[a].grade;
cout << '\n';
}
system("cls");
cout << "1 - Add";
cout << "2 - Delete";
cout << "3 - Search";
cout << "4 - Print";
cout << "5 - Exit";
string lname, fname;
int choice, search;
cin >> choice;
if(choice == 3) {
cin >> fname;
cin >> lname;
int index = search;
(SD2, lname, fname, last);
if (index > 0) {
cout << "ERROR\n";
}
else {
cout << "The grade of " << lname << "," << fname << "is " << SD2[index].grade;
}
}
int search(SD list [], string search_lname, string search_fname, int last) {
int index;
if(isEmpty(last)==1) {
cout << "\nThe list is Empty!";
}
else {
index = 0;
while(index!= last+1 && list[index].name.first != search_fname && list[index].name.last != search_lname) {
++index;
}
if(index != last + 1) {
cout << "\nItem Requested is Item" << index + 1 << ".";
return index;
}
else {
cout << "\n Item Does Not Exist.";
}
}
return -1; // list is empty or search item does not exist
}
}
을 확인했습니다 비록 내 코드의 문제점이 무엇인지 알 수
main()
에서 : 문제의
[mcve]를 제공하기 위해 질문을 편집하십시오. –
코드를 작성할 때 완벽하게 작동하는 작고 간단한 것으로 시작한 다음 한 번에 조금씩 복잡성을 추가하십시오. 가능한 한 격리 된 새로운 기능을 개발하십시오. 모든 단계에서 테스트하고 ** 작동하지 않는 코드에 ** 추가하지 마십시오 ** – Beta
main() 함수는 _void_ 유형의 반환 값을 가질 수 없습니다. –