Hi,

I'm fairly new to c++ and I'm having some trouble getting this to work as a function.

Here's the error I get:

error C2447: '{' : missing function header (old-style formal list?)

I can work through the minor troubleshooting of basic syntax I just don't get how to call the function properly.

Thanks!!

here's the code:

#include<iostream>// calls I/O library
usingnamespace std;
double sales;//declare sales as a double so decimals can be used
void salesInput()//Sales Input Function
{
const double basePay = 200;//declare base salary as a constant 
const double grossSales = .09;//declare gross sales as a constant
double com;//declare commission as double so decimals can be used
com=((sales * 0.09) + 200);//calculation for commission
cout << "Total pay plus 9% commission is " <<com << endl;//output final results to the screen
}
usingnamespace std;
int main();
{
cout << "Enter the Sales for the week, enter a zero to quit"<< endl; //ask user for input
cin >> sales;//get input and store as variable sales
while (sales != 0 )//Start sales loop, executes function sales input if anything other than a zero is entered, if zero then exit
{
salesInput();//calls sales input function
}
cout << “You entered a zero to quit!” << endl;
return0;
}

Recommended Answers

All 6 Replies

remove the semicolon at the end of line 13. That's a common mistake for even old-timers -- you just need to learn how to recognize the error.

remove the semicolon at the end of line 13. That's a common mistake for even old-timers -- you just need to learn how to recognize the error.

OK fixed that (thanks) and I removed line 21 which was causing an error (I'll fix that later). Problem now is I'm in a continuous loop, which is what I had before I tried to make a function out of it. How do I make it execute the function once then return to ask if there is another amount to put in?

Thanks!

also delete line 12, don't have to declare that only once at the top of the program and after the includes.

>>How do I make it execute the function once then return to ask if there is another amount

move lines 17 and 18 up above line 15. Also, there is no need to make sales a global variable. Move line 3 to be local to main() then pass it as a parameter to salesInput() function.

also delete line 12, don't have to declare that only once at the top of the program and after the includes.

>>How do I make it execute the function once then return to ask if there is another amount

move lines 17 and 18 up above line 15. Also, there is no need to make sales a global variable. Move line 3 to be local to main() then pass it as a parameter to salesInput() function.

OK, still problems. It compiles but now it goes straight to the "Press any key to continue"

1 #include <iostream>// calls I/O library
2 using namespace std;
3 double sales;//declare sales as a double so decimals can be used
4 double salesInput()//Sales Input Function
5 {
6 const double basePay = 200;//declare base salary as a constant
7 const double grossSales = .09;//declare gross sales as a constant
8 double com;//declare commission as double so decimals can be used
9 com=((sales * 0.09) + 200);//calculation for commission
10 cout << "Total pay plus 9% commission is " <<com << endl;//output final results to the screen
11}
12 int main()
13{
14 while
15 (sales!=0 )//Start sales loop, executes function sales input if anything other than a zero is entered, if zero then exit
16 {
17 cout << "Enter the Sales for the week, enter a zero to quit"<< endl; //ask user for input
18 cin >> sales;//get input and store as variable sales
19 salesInput();//calls sales input function
20 }
21 }

What's the value of sales when the program starts?

And use Code Tags!

What's the value of sales when the program starts?

And use Code Tags!

Sorry about the code tags, my bad. But that was it, I simply added a sales=1 at the beginning and it worked.

Thanks for the help!!

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.