| | |
Function help/homework
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: May 2007
Posts: 6
Reputation:
Solved Threads: 0
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:
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:
c Syntax (Toggle Plain Text)
#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; }
Last edited by Ancient Dragon; May 7th, 2007 at 9:54 pm. Reason: removed color codes and added code tags to show line numbers
•
•
Join Date: May 2007
Posts: 6
Reputation:
Solved Threads: 0
•
•
•
•
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.
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.
>>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.
•
•
Join Date: May 2007
Posts: 6
Reputation:
Solved Threads: 0
•
•
•
•
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.
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 }
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: May 2007
Posts: 6
Reputation:
Solved Threads: 0
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!!
Thanks for the help!!
![]() |
Similar Threads
- calculatecharges function (C++)
- Passing a matrix from main function to user defined function. (C++)
- Homework: filling array from text file (VB.NET)
- error C2447: missing function header (old-style formal list?), what does this mean?! (C++)
- Arrays Assignment!!! (C++)
- Function that returns void (C++)
- Homework Help!! Priority Queue ?? (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: Pascal -> C++; Binary, convert?
- Next Thread: How To Read A Webpage ?
Views: 1358 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






