Nothing will print out.

As the title says, I can't seem to get anything to print out. The point of the code is to be able to take the alternating sums of two vectors and add them all together. As far as I can see, I honestly think that I need a fresh pair of eyes to find my error in the code.

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
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
double input(std::vector<double> val1, std::vector<double> val2) 
{
	int i;
	std::vector<double> val3;
	double vector_sum;
	for(i = 0;i<val1.size();i++)
	{
	if ((i%2) == 0)
	{
		val1[i]+=val2[i];
	}
	else
	{
		val1[i]-=val2[i];
	}
	val3.push_back(val1[i]);
	}
	vector_sum = std::accumulate(val3.begin(), val3.end(),0);
	return vector_sum;
}


int main(int argc, char** argv)
 {
 	using std::cout;
 	using std::cin;
 	double a;
 	double b;
 	std::string awnser;
 	bool x;
 	x = 1;
 	std::vector<double> ar_1;
 	std::vector<double> ar_2;
 	while(x = 1)
 	{
 	cout << "Please enter a number: ";
 	cin >> a;
 	cout << "Please enter another number: ";
 	cin >> b;
 	ar_1.push_back(a);
 	ar_2.push_back(b);
	double alt_sum = input(ar_1,ar_2);
	cout << "Would you like to enter more variables? (y/n)";
	cin >> awnser;
	if (awnser == "n")
	{
		x = 0;
		break;
		cout << alt_sum;
	}
	}	
	return 0;
}
Last edited on
while(x = 1)

Should be while(x == 1)

= is an assignment operator.
== is the "equal to" operator.

You want to check if x is equal to 1 and not give x the value 1.
Topic archived. No new replies allowed.