Variable error?

I am working on this code and I finished but i have 2 errors on line 19 about variables y and m, saying that they are uninitialized local variables. I don't see how this is possible because I declared them at the beginning and their value is assigned when the user inputs in cin. If you could help me find the problem that would be great.

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
#include <iostream>
#include <string>
#include <cmath>
#include <math.h>
#include <vector>

using namespace std;

int main()
{
	int a, b, n, max = 0;

	cin >> a, b, n;

	for (int i = 0; i < 20; i++)
	{
		for (int j = 0; j < 20; j++)
		{
			if (max < (i*a + j*b) && (i*a + j*b) <= n)
				max = i*a + j*b;
		}
	}

	cout << max;

	return 0;
}
Last edited on
i have 2 errors on line 19 about variables y and m, saying that they are uninitialized local variables.

y and m? I dont see y and m anywhere.

cin >> a, b, n;
This is not doing what you think it's doing. It should be cin >> a >> b >> n;
Thanks!!!
Topic archived. No new replies allowed.