2016-07-06 106 views
-1

这是我在stackoverflow上的第一个问题,所以我希望它都出来格式正确。我正在编写我的编程课程,我们必须编写一个程序,它接受两个输入,然后产生结果读数。我必须创建两个功能来询问一个人想要参加哪个音乐会,然后他们想要为该音乐会购买多少票。我已经创建了这些函数,但是现在我无法调用函数来打印我的结果。调用C++函数

#include <iostream> 
using namespace std; 

char GetConcert() 
{ 
    char Concert; 
    cout << "The following concerts are available:\n"; 
    cout << "  B for Beyonce\n"; 
    cout << "  L for Lady Gaga\n"; 
    cout << "  T for Taylor Swift\n"; 
    cout << "Enter the letter for the concert you want:\n"; 
    cin >> Concert; 
    return Concert; 
} 

int GetNumTickets() 
{ 
    int NumTickets; 
    cout << "Enter the number of tickets you want:\n"; 
    cin >> NumTickets; 
    while ((NumTickets < 0) || (NumTickets > 10)) 
    { 
     if (NumTickets < 0) 
     cout << "You can not sell tickets here.\n"; 
     else if (NumTickets > 10) 
     cout << "You may not purchase more than 10 tickets.\n"; 
     cout << "Enter the number oftickets you want:\n"; 
     cin >> NumTickets; 
    } 
    return NumTickets; 
} 

int main() 
{ 
    // Declare Variables 
    char Concert; 
    int NumTickets; 

    // Call function to find out the concert they want to attend 


    // Call function to find out how many tickets they want 

    // Print out the information you have collected. 
    cout << "\nThe customer has placed the following order:\n"; 
    cout << "Concert: " << Concert << endl; 
    cout << "Number of Tickets: " << NumTickets << endl; 
    return 0; 
} 

我宣布我的主段中的变量,但是当我尝试调用的函数,它说,我不能从整数转换为字符。

+0

显示触发错误的代码。显示错误信息的确切完整文本;不要复述。 –

+0

main.cpp | 40 |错误:从'char(*)()'无效转换为'int'[-fpermissive] | – Lumberjacked216

+0

第40行main.cpp中的代码是什么? –

回答

1

为了在C++中调用函数,你需要在函数名的末尾加上()。在这个例子中,GetNumTickets()GetConcert()。由于这些函数也是返回值,因此保存返回值以便稍后使用或立即使用它们非常重要。您可以尝试:

char Concert = GetConcert(); 
int NumTickets = GetNumTickets();