structure

Im getting a logic error its adding up the feet and yards properly but the conversion is off. its just adding the feet and not converting them into yards



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

struct Distance
{
	int yards;
	int feet;
	
}d1, d2, sum;


int main()
{ 
	
	cout << "Enter First Distance\n";
	cout << "Enter Distance Of Feet";
	cin >> d1.feet;
	cout << "Enter Distance Of Yards";
	cin >> d1.yards;
	cout << "Enter Second Distance\n";
	cout << "Enter Distance Of Feet";
	cin >> d2.feet;
	cout << "Enter Distance Of Yards\n";
	cin >> d2.yards;
	
	if (sum.feet>=3)
	{
		sum.yards++;
	}
	
	sum.feet = d1.feet + d2.feet;
	sum.yards = d1.yards + d2.yards;

	
	cout << "The Sum Of The Distance In Feet\n" << sum.feet;
	cout << "The Sum Of The Distance In Yards\n" << sum.yards;
	
	
	
	system("pause");
	return 0;

} 
First of all sum.feet has no assigned value when you check with the if statement

1
2
3
4
if (sum.feet>=3)
{
      sum.yards++;
}
Topic archived. No new replies allowed.