listSelectedDVD()當我輸入標題時應該顯示細節。但在我的代碼我能夠輸入標題,但沒有顯示details.unable傳入參數。在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
這是我void初始化() & 無效listSelectedDVD(字符串enterTitle)的void函數;
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'還是'Just Just Enough'? – LP496
當使用'cin >> enterTitle;'時,找不到名字空格的標題。使用調試器來解決這類問題,而不是使用stackoverflow – grek40