function definition error
Sep 24, 2013 at 10:43am UTC
Hi , anyone please help this error In function void computeKilosPerHour (float ,float, float)
error a function definition is not allowed here before '{' token . I cant figure out what is wrong
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <iostream>
#include <iomanip>
using namespace std;
void printDescription ( )
{
cout << "**************************************************************" << endl;
cout << "This program takes two numbers (kilometers and hours)" <<endl;
cout << "and outputs the average speed travelled" << endl;
cout << "**************************************************************" << endl;
}
void computeKilosPerHour (float kilos, float hours, float average)
{
int main ()
{
float kilos, hours, average;
cout << "Welcome to the Travel Calculator" << endl;
printDescription();
cout << "Please input the kilometers travelled" << endl;
cin >> kilos;
cout <<"Please input the hours travelled" << endl;
cin >> hours;
computeKilosPerHour(kilos, hours);
}
average= kilos/hours;
cout << "Your average speed was" << average << "km per hour" << endl;
cout << "We hope you enjoyed this program" << endl ;
return ;
}
Sep 24, 2013 at 10:50am UTC
Indentation might explain:
1 2 3 4 5 6 7 8
void computeKilosPerHour (float kilos, float hours, float average)
{
int main ()
{
// statements
}
// statements
}
The compiler does not like about the attempt to define a function inside definition of a function.
Sep 24, 2013 at 11:07am UTC
ok so how do i rectify it , im sorry still a bit of a dummy in programming
Sep 24, 2013 at 11:15am UTC
Compiler does not complain about your another function (printD..), does it?
Sep 24, 2013 at 11:30am UTC
no it doesnt
Sep 24, 2013 at 12:44pm UTC
ok so how do i rectify it
Don't try and define a function inside another function.
Sep 24, 2013 at 1:01pm UTC
mov main, outside_computeKilosPerHour
Sep 24, 2013 at 1:07pm UTC
thank you all
Topic archived. No new replies allowed.