0
#include <iostream>
#include "stdlib.h"

using namespace std;

struct var{
int a;
int b;
int result;

};

void adD(var&);

int main()
{
int a;
int b;
cout<<"please ente the value a ====  "<<endl;
cin>>a;
cout<<"please ente the value b ====  "<<endl;
cin>>b;
var v1;
adD(v1);

 system("cls");
 cout<<"the value of result ==  "<<v1.result<<endl;
 return 0;
}
void adD(var& v1){

v1.result = (v1.a)+(v1.b);

}

Edited by Narue: added code tags (not that it helped)

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by tajendra
0

I don't know what you are asking for but you need to cin >> v.a >> v.b [\i]. Make sure you define var v before using it in cin

0

First of all you need to put your code in the code tags, second of all, what's the problem you are having?

Edited by Cross213: n/a

0

Yes, that's right what firstPerson is saying, you are adding variables that have not been given values, v1.a and v1.b are being added but have not been assigned values.

0

Yes structure can be passed by reference. As firstPerson said you must take input in structure or you can initialize your structure with values a and b.

v1.a = a;
v1.b = b;

Write above code after declaration of var v1 and before calling function adD(v1);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.