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:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` ``````#include 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); } }``````

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.

 ``1234567891011121314151617181920212223242526`` ``````#include using namespace std; void c_accumulation(float ¤t, 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
Is that what you're looking for

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546`` ``````# include # include 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.