how to pass down values?

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

short unsigned int choice = 0;
short unsigned int sss = 0;

void breakfast();
void lunch();
void snack();
void dinner();
void desert();

int main()
{
	char answer;
	short unsigned int i = 0;
	cout<<"yes or no"<<endl;
	cin>>answer;
	if (answer = 'y')
	{
		i = (i + 1);
	}
	else 
	{
		i = (i + 2);
	}

		cout<<"yes or no"<<endl;
	cin>>answer;
	if (answer = 'y')
	{
		i = (i + 1);
	}
	else 
	{
		i = (i + 2);
	}
	cout<<i;
}


ignore those prototypes i just want to know how to pass down i? i mean if my first answer is y and my second answer is n, i want the cout to be 3 which is 1+2 but it is displaying 2 instead.

Actually i want that pass down thing to have global effect. E.g the code i have in main will be in one of the functions i call the function in main then display i.
Last edited on
closed account (3hM2Nwbp)
1
2
3
4
5
//assignment
int x = 4;

//equality
if(x == 4)
+1 Luc Lieber

@jimmy: look at lines 19, 30
No i don't want that.

ok here's what i want

int x = 0;
cout<<x;//0
x = x+1;
cout<<x//1
x = x+1
cout<<x//2 NOT 1 but 2 how i do that?
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
#include<iostream>
using namespace std;

short unsigned int choice = 0;
short unsigned int sss = 0;

void breakfast();
void lunch();
void snack();
void dinner();
void desert();

int main()
{
	char answer;
	short unsigned int i = 0;
	cout<<"yes or no"<<endl;
	cin>>answer;
	if (answer == 'y') // ==
	{
		i = (i + 1);
	}
	else
	{
		i = (i + 2);
	}

		cout<<"yes or no"<<endl;
	cin>>answer;
	if (answer == 'y') // ==
	{
		i = (i + 1);
	}
	else
	{
		i = (i + 2);
	}
	cout<<i;
}

Run this and enter first 'y' and then 'n'
Last edited on
Topic archived. No new replies allowed.