Jump to content

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
https://linustechtips.com/topic/126775-c-functions/
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
https://linustechtips.com/topic/126775-c-functions/#findComment-1686121
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 :) 

ZerueLX11

Check me out! LTT Forum Profile!

Link to comment
https://linustechtips.com/topic/126775-c-functions/#findComment-1687260
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

×