โอเค ฉันยังใหม่กับเรื่องนี้มาก และฉันกำลังพยายามสร้างโปรแกรมที่จะคำนวณค่าโทรทางไกลจำนวนเท่าใดก็ได้ ฉันยังไปได้ไม่ไกลนัก ฉันติดอยู่กับการพยายามหาวิธีให้ฟังก์ชันทำซ้ำตัวเอง ตอนนี้ฉันได้รับข้อผิดพลาดที่บอกว่า
บรรทัดที่ 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;
}
costCalc()
ของคุณขึ้นไปด้านบนmain()
- person twalberg   schedule 05.02.2014C
เลยเหรอ? ฉันไม่เคยเห็นusing namespace std;
ทั้งcin
หรือcout
ในแหล่งที่มาC
ใดๆ เลย... (หากฉันเข้าใจผิด ฉันก็ยังเป็นมือใหม่C
เช่นกัน) - person core1024   schedule 05.02.2014C
; มันคือC++
ไม่รองรับสตรีมในC
- person Stephen Rasku   schedule 05.02.2014