Итак, я очень к этому отношусь, и я пытаюсь создать программу, которая будет вычислять стоимость любого количества междугородних звонков. Я еще не очень далеко, я застрял, пытаясь понять, как заставить функцию повториться. Прямо сейчас я получаю сообщение об ошибкеСоздание функции цикла для вычисления стоимости
Строка 18 здесь не допускается определение функции перед '{' токеном и ожидаемым ',' или ';' перед '{' токеном.
Линия 18 является линией непосредственно послеvoid costCalc(int numCalls)
Вот мой код до сих пор:
#include<iostream>
using namespace std;
int main()
{
// Declare and initialize all variables
int numCalls = 0;
int length = 0;
int hour = 0;
char day = ' ';
char dest = ' ';
double cost = 0.0;
cout<<"Enter the number of calls: ";
cin>>numCalls;
void costCalc(int numCalls)
{
if (numCalls > 0)
{
cout<<"Enter length of call in minutes: ";
cin>>length;
costCalc(numCalls-1);
}
}
// Request the number of calls from the user
// Loop for the requested number of calls:
// Request the user to give you the call length,
// call day of week and hour of call, and call
// destination
// Instantiate and initialize a Call object
// using either
// a) the 4-parameter constructor, OR
// b) the default constructor and each of the
// set member functions.
// Get the cost of the call using the calcCallCost
// function and add it to the total cost of the calls.
// Use the callMsg function to print a message about the call
// end loop
// Report the total cost of all the calls.
system("pause");
return 0;
}
У вас есть функция, объявленная в функции. Переместите фигурные скобки. Кроме того, хорошее использование рекурсии для нового программиста. –
C не разрешает вложенные функции, как указано в @WilliamCustode - переместить вашу функцию 'costCalc()' до значения выше 'main()'. – twalberg
Действительно ли это 'C'? Я не видел 'using namespace std;' ни 'cin', ни' cout' внутри какого-либо источника 'C' ... (исправьте меня, если я ошибаюсь. Я тоже' C') – core1024