Function help/homework

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: May 2007
Posts: 6
Reputation: ssgatbliss is an unknown quantity at this point 
Solved Threads: 0
ssgatbliss ssgatbliss is offline Offline
Newbie Poster

Function help/homework

 
0
  #1
May 7th, 2007
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:
  1. #include<iostream>// calls I/O library
  2. usingnamespace std;
  3. double sales;//declare sales as a double so decimals can be used
  4. void 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. usingnamespace std;
  13. int main();
  14. {
  15. cout << "Enter the Sales for the week, enter a zero to quit"<< endl; //ask user for input
  16. cin >> sales;//get input and store as variable sales
  17. while (sales != 0 )//Start sales loop, executes function sales input if anything other than a zero is entered, if zero then exit
  18. {
  19. salesInput();//calls sales input function
  20. }
  21. cout << “You entered a zero to quit!” << endl;
  22. return0;
  23. }
Last edited by Ancient Dragon; May 7th, 2007 at 9:54 pm. Reason: removed color codes and added code tags to show line numbers
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,672
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Function help/homework

 
0
  #2
May 7th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 6
Reputation: ssgatbliss is an unknown quantity at this point 
Solved Threads: 0
ssgatbliss ssgatbliss is offline Offline
Newbie Poster

Re: Function help/homework

 
0
  #3
May 7th, 2007
Originally Posted by Ancient Dragon View Post
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!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,672
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Function help/homework

 
0
  #4
May 7th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 6
Reputation: ssgatbliss is an unknown quantity at this point 
Solved Threads: 0
ssgatbliss ssgatbliss is offline Offline
Newbie Poster

Re: Function help/homework

 
0
  #5
May 8th, 2007
Originally Posted by Ancient Dragon View Post
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 }
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,131
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 283
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Function help/homework

 
0
  #6
May 8th, 2007
What's the value of sales when the program starts?

And use Code Tags!
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 6
Reputation: ssgatbliss is an unknown quantity at this point 
Solved Threads: 0
ssgatbliss ssgatbliss is offline Offline
Newbie Poster

Re: Function help/homework

 
0
  #7
May 8th, 2007
Originally Posted by WaltP View Post
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!!

Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1358 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC