listSelectedDVD()은 제목을 입력 할 때 세부 사항을 표시해야합니다. 하지만 내 코드에서 제목을 입력 할 수 있지만 세부 사항을 표시하지 못했습니다. 인수에서 전달할 수 없습니다. 여기 IF 문에서 void 함수를 호출합니다. C++
#include <iostream>
#include <string>
using namespace std;
struct myStock // declare myStock fields
{
string title;
double price;
int stockLevel;
bool award;
};//end of strcut myStock
myStock list[5];
void initialize();
void listSelectedDVD(string);
int main()
{
int choice;
string enterTitle;
cout << "****** MAIN MENU ******" << endl;
cout << "1. List deatils of selected title" << endl;
cout << "4. Exit" << endl;
cout << endl;
cout << "enter your choice: " << endl;
cin >> choice;
if (choice == 1)
{
cout << "Enter a Title: " << endl;
cin >> enterTitle;
listSelectedDVD(enterTitle);
}
else if (choice == 4)
{
return 0;
}
system("PAUSE");
}//end of main
는
무효 초기화() &
무효 listSelectedDVD (문자열 enterTitle)의 내 무효 기능입니다;
void initialize()
{
list[0].title = "Ilo Ilo";
list[0].price = 35.55;
list[0].stockLevel = 15;
list[0].award = true;
list[1].title = "Money Just Enough";
list[1].price = 10.35;
list[1].stockLevel = 0;
list[1].award = false;
}
void listSelectedDVD(string enterTitle)
{
for(int i=0;i<5;i++)
{
if (list[i].title.compare(enterTitle) == 0) //list[i].title == enterTitle
{
cout << "Title : " << list[i].title << endl;
cout << "Price : " << list[i].price << endl;
cout << "Stock : " << list[i].stockLevel << endl;
cout << "Award : " << list[i].award << endl;
}
else {
out<<"Invalid Title"<<endl;
//call back the main menu function//
}
}
}
일련의 이벤트를 제공해야하는 것처럼 보입니다. 현재로서는 제목이 존재하지 않는다는 단순한 대답 일 수 있습니다. – ChiefTwoPencils
현재 어떤 출력물을 제공 할 수 있습니까? 아니면 그냥 공백입니까? 또한'enterTitle'이'Ilo Ilo' 또는'Money Just Enough'입니까? – LP496
'cin >> enterTitle;'을 사용할 때 이름에 공백이있는 제목이 없습니다. 이러한 종류의 문제가 아니라 디버거를 사용 stackoverflow – grek40