Jump to content

C++ functions

Skreedles

I have a program with a few functions and each function has a while statement in the function.

 

My problem is every time I add data into one statement the data is added into the next funtion without me telling it to.

 

ex:

 

Main

call func1(total)

call func2(total)

call func3(total)

 

func 1

1

1

1

1

1

total is 5

cout total: 5

 

func 2

1

1

1

1

1

total is 10

Link to comment
Share on other sites

Link to post
Share on other sites

Probably because you are passing the value by reference and manipulating that in your functions. Your func1 is probably doing total += 1? which changes total's value in general if I'm correct. Try not passing by reference func1(int& total) -> func1(int total) or don't manipulate total in func1. Though I can only trouble shoot so much without actually seeing code.

Link to comment
Share on other sites

Link to post
Share on other sites

I have a program with a few functions and each function has a while statement in the function.

 

My problem is every time I add data into one statement the data is added into the next funtion without me telling it to.

 

ex:

 

Main

call func1(total)

call func2(total)

call func3(total)

 

func 1

1

1

1

1

1

total is 5

cout total: 5

 

func 2

1

1

1

1

1

total is 10

 

Please do post your code :) 

[ Cruel Angel ]:     Exterior  -   BENQ XL2420T   |   SteelSeries MLG Sensei   |   Corsair K70 RED   |   Corsair 900D  |                                                                                                    CPU:    -   4.7Ghz @ 1.425v             |

                             Interior    -   i7 4770k   |    Maximus VI Formula    |   Corsair Vengeance Pro 16GB    |   ASUS GTX 980 Strix SLIx2  |  840 Pro 512Gb    |    WD Black 2TB  |           RAM:   -   2400Mhz OC @ 1.650v    |

                             Cooling   -   XSPC 120mm x7 Total Radiator Space   |   XSPC RayStorm    |    PrimoChill Tubing/Res  |                                                                                             GPU:   -   1000Mhz @ 1.158            |

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×