output problem

hey ppl

i dono wats wrong with this ??
could any one tell me the output of this & what are the values of x, y, z when the program ends?

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
47
48
49
50
51
52
53
#include <iostream>
using namespace std;

void function1(int &, int &);
int function2(int &);
int function3(int , int);
void function4(int, int, int);

void main()
{
int x = 9, y = 7, z = 5;

for(int i = 0; i<= 5; i++)
function1(x, y);;

z = function2 ( y );

if((z>=10 && x<7) || y!= 5)
{
y = function3(x,9);
x = function3(y,9);
}
else
z = function3(z,x);

function4(x, y, z);
system("pause");
}
void function1(int &a, int &b)
{
a++;
b--;
if(a == b)
a = 2*b;
else
b = a%2;
}
int function2( int & a )
{
a+=2;
return 10;

}

int function3(int a, int b)
{
return a*2+b/2;
}

void function4(int a, int b, int c)
{
cout << "The Result is: " << (a+b)/c << endl;
}
Fix the errors (main returns an int) and then build it and run it.
i asked my teacher he told me its ok like this

ust find the output ??
its kinda tricky question
Why don't you just run the program and see what the output you get?
i got 10 but am not sure !! dat why i am asking
what about x , y ,z ?? when the Program ends ???
mebbe u cud put in like cout << x; when u want no wat x is
when i put it at the end i get an error !!!
Why are you returning a 10 in function2(), instead of the actual results of a+=2, which in this case, would be a 9?

i didnt wrote the code its not me .. i just have to find x , y, and z !! (when the Program ends)
@wizo0o

I added cout's to the functions to show what the values are in each. Pretty much what Moschops was telling you that you should do. I print out what function you're in, and the values. For the final answer, remember that integers are whole numbers, so you will not get a point something.
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Output Problem.cpp : main project file.

#include "stdafx.h"
#include <iostream>

using namespace std;

void function1(int &, int &);
int function2(int &);
int function3(int , int);
void function4(int, int, int);

void main()
{
int x = 9, y = 7, z = 5;

for(int i = 0; i<= 5; i++)
function1(x, y);;

z = function2 ( y );

if((z>=10 && x<7) || y!= 5)
{
y = function3(x,9);
x = function3(y,9);
}
else
z = function3(z,x);

function4(x, y, z);
system("pause");
}
void function1(int &a, int &b)
{
cout << "In function1.." <<endl;
a++;
b--;
if(a == b)
a = 2*b;
else
b = a%2;
cout << "a = : " << a << "  --- b = : " << b << endl;
}

int function2( int & a )
{
cout << "In function2.." <<endl;
a+=2;
cout << "a = : " << a << endl;
return 10;

}

int function3(int a, int b)
{
cout << "In function3.." <<endl;
	cout << "a = : " << a << "  --- b = : " << b << endl;
return a*2+b/2;
}

void function4(int a, int b, int c)
{
cout << "In function4.." <<endl;
cout << "a = " << a << " b = " << b << " c = " << c << endl;
cout << "The Result is: " << (a+b)/c << endl;
}
Last edited on
Topic archived. No new replies allowed.