Arithmetic sequence

Hey guys, im building a program that recieves 3 numbers,the a1, the difference and the lengh of the sequence.(a1,d,n)

I need help with the choosing manue, somehow the "if" dosent work.
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
67
68
69
70
71
72
73
74
{
		#include <iostream>

using namespace std;


void func1(double a1, double d, double n, double &z);
void func2(double a1, double d, double n, double &z);
int main()
{

	double a1, d, n,z;
	int o;
	cout << "Welcome, to the greatest formula calculator of all times. Please choose an operation dear user:" << endl << "0 - End" << endl << "1 - Aritmethic" << endl << "2 - Geometric"<<endl;
	cin >> o;

	if(o=2)
	{
		cout << "Please enter a1,d and n" << endl;
		cin >> a1 >> d >> n;
		z = a1;


		func2(a1, d, n, z);
		cout << z;
	}



	if (o =1)
	{
		cout << "Please enter a1,d and n" << endl;
		cin >> a1 >> d >> n;
		z = a1;


		func1(a1, d, n, z);
		cout << z;
	}

	if(o=0)
	{
		cout << "Thank you for using my program"<<endl;
		return 0;
	}
	
}


void func1(double a1, double d, double n, double &z)

{

	for (int i = 0; i<(n-1); i = i + 1)
	{
		cout << z << " ";
		z = z + d;

	}

}

void func2(double a1, double d, double n, double &z)
{
	for (int i = 0; i<(n - 1); i = i + 1)
	{
		cout << z << " ";
		z = z * d;

	}

}

	}
Last edited on
You are using = (assignment) when you want == (equality).
Topic archived. No new replies allowed.