help passing values between functions!!

I'm having trouble passing values from the first function to the second without program terminating at calculating, this my my code so far.


#include<iostream>
#include<iomanip>
#include<functional>
using namespace std;
int main()
{
double calcCom();
double salesmanID,baseSalary,baseSales;
double personalcomp,printers,access,maint;
cout<<"Please enter a salesman ID Number"<<endl;
cin>>salesmanID;

cout<<"Please enter a base salary"<<endl;
cin>>baseSalary;
cout<<"Please enter a sales amount for each catergory"<<endl;

cout<<"Personal Computers:"<<endl;

cin>>personalcomp;
cout<<"Printers:"<<endl;

cin>>printers;
cout<<"Accessories:"<<endl;

cin>>access;
cout<<"Maintenace:"<<endl;

cin>>maint;
cout<<"Calculating..."<<endl;

double calcComm(double basesalary,double sales,double percent);{
double compBonus,accessBonus,maintBonus,printerBonus,totalCom,totalDue;




if(personalcomp>=6000)
{
compBonus=(personalcomp*.12);}
else compBonus=0;
if(printers>=2500)
{
printerBonus=(printers*.10);}
else printerBonus=0;
if(access>=2000)
{
accessBonus=(access*.10);}
else accessBonus=0;
if(maint>=1500)
{maintBonus=(maint*.06);}
else maintBonus=0;
return compBonus, printerBonus,accessBonus,maintBonus;
}


void calcComm(double compBonus,double accessBonus,double maintBonus,double printerBonus,double totalCom,double totalDue);{
double compBonus,accessBonus,maintBonus,printerBonus,totalCom,totalDue;

cout<<fixed<<setprecision(2);

cout<<setw(40)<<"My Computer Company"<<endl<<endl;
cout<<setw(40)<<"Commission Satement"<<endl<<endl;
cout<<setw(35)<<"Salesman ID:"<<" "<<salesmanID<<endl<<endl;
for (int x = 1; x < 4; x++ )
{for(int x=1;x<5;x++){
cout<<fixed<<setprecision(2);
cout<<setw(20)<<"Product"<<" "<<setw(20)<<"Sales Amount"<<setw(20)<<" "<<"Comission"<<endl<<endl;
cout<<setw(20)<<"Personal Computers"<<" "<<setw(20)<<personalcomp<<setw(20)<<" "<<compBonus<<endl;
cout<<setw(20)<<"Printers"<<" "<<setw(20)<<printers<<setw(20)<<" "<<printerBonus<<endl;
cout<<setw(20)<<"Accessories"<<" "<<setw(20)<<access<<setw(20)<<" "<<accessBonus<<endl;
cout<<setw(20)<<"Maintenance"<<" "<<setw(20)<<maint<<setw(20)<<" "<<maintBonus<<endl;
cout<<endl<<endl;



totalCom=compBonus+printerBonus+accessBonus+maintBonus;
totalDue=baseSalary+totalCom;
int y;

for (int i= 1; i < 3; i++ )
{for(int i=1;i<4;i++){
14
;cout<<"Total Commission:"<<totalCom<<endl;
cout<<"Base Pay:"<<baseSalary<<endl;
cout<<"Total Due:"<<totalDue<<endl;
system("Pause");
cout<<"Please enter -999 to exit program"<<endl;

}}}
}
}
your code is completely wrong .. please go through function tutorial in c and c++.
A function may not be defined inside a body of other function in C/C++. So you have to define your function calcComm outside the main function.
Use the 'code' tags when posting code, it makes it easier to understand, because it will look like this:

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
40
41
42
43
44
45
#include<iostream>
#include<iomanip>
#include<functional>
/* Don't use using namespace keywords, all you are doing is
putting everything in the std scope. Qualify your variables correctly:
std::cout, std::cin, std::endl, std::string, etc */
using namespace std;
int main()
{ // I also suggest you use identation, it is easier to read your code that way

double calcCom(); /* I guess you are declaring a function's prototype here
                    maybe? Prototypes go outside the main function, right
                    where you placed the using namespace keywords */

// All this is OK so far
double salesmanID,baseSalary,baseSales;
double personalcomp,printers,access,maint;
cout<<"Please enter a salesman ID Number"<<endl;
cin>>salesmanID;

cout<<"Please enter a base salary"<<endl;
cin>>baseSalary;
cout<<"Please enter a sales amount for each catergory"<<endl;

cout<<"Personal Computers:"<<endl;

cin>>personalcomp;
cout<<"Printers:"<<endl;

cin>>printers;
cout<<"Accessories:"<<endl;

cin>>access;
cout<<"Maintenace:"<<endl;

cin>>maint;
cout<<"Calculating..."<<endl;
// Here you would place your calcCom() function
// main function would end here

/* From here on, you have WAY too many errors to point each one of them.
Follow bluecoder's suggestion and check the links I posted.
Another suggestion: be cleaner with your code! It will make it easier for
us and for yourself to find errors and understand the logic of your
program*/


First check out these links and if you have any other questions, feel free to ask again:
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/

Also you urgently need to read something about good programming practices!!
Last edited on
Topic archived. No new replies allowed.