void function

im a beginner in void function... my knowledge about void functions aren't that good. i just want to ask your help in this. i want to total all the commission but i don't know how..
here is my code:
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
#include <iostream>
using namespace std;

void calculatecomm(float y)
{
     float Commission = y  * .10;
}
void displaycomm(float x)
{
  cout << " The commission is: $" << x * .10 << endl;
}
void totalcomm(float total)
{
     float sc = 0;
     total = total + sc;
     cout << " total : " << total << endl;
}
float getsales(float &s1)
{
         float g = 0;
         cout << endl << " Input negative number to exit " << endl;
         cout << " Enter sales amount: $";
         cin >> s1;
         
         while (s1 < 0)
         {     
               totalcomm(s1);
               system("pause");
               exit(0);
         }       
}
int main()
{       
        float s1,s2,i;
        
        for ( i = 0; ;i++ )
        { 
            getsales(s1);
            displaycomm(s1);
        }
       
}


your help is really needed.. tnx in advance
I am not very sure about what are u trying to achieve. I got a code which u can sum the commission of the previous sales and the current sales.

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
#include <iostream>
using namespace std;

void c_accumulation(float &current, float &prev)
{
     float &a = current;
     float &b = prev;
     
     a = a*0.1 + prev;
     prev = a;
}

int main()
{
    float s1=0, s2=0;
    cout << "enter ur commision, -1 to exit: ";
    cin >> s1;
    while (s1>0)
    {
          c_accumulation(s1, s2);
          cout << "total commision is: " << s1 << endl;
          cout << "sum: ";
          cin >> s1;
    }
    return 0;
}


void function is very simple, they can return nothing. But for other func like int, float... will return their respective type value.
but the problem needs this:

a value returning function to get the amount sold by a person
a void function to calculate the 10% commission
another void function to display the commission
and another void function to calculate the total commission

... that is why i have those codes
closed account (28poGNh0)
Is that what you're looking for

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
46
# include <iostream>
# include <limits.h>
using namespace std;


void calculatecomm(float &y)
{
    y = float(y) * 0.1;
}

void displaycomm(float x)
{
    cout << " The commission is : " << x << " $ " << endl;
}

void totalcomm(float total)
{
    cout << " total : " << total << endl;
}

float getsales(void)
{
    int var = 0;
    cout << "Enter sales amount -> ";
    cin >> var;

    return var;
}

int main()
{
    float comSum = 0;

    for (int i=0;;i++)
    {
        float tmpVar = getsales();
        if(tmpVar<0)break;
        calculatecomm(tmpVar);
        displaycomm(tmpVar);
        comSum += tmpVar;
    }

    totalcomm(comSum);

    cin.ignore(INT_MAX);
}
thank you so much.. i'll just revise it so that i can understand the code ... thank you again
Topic archived. No new replies allowed.