Last edited on
It keeps giving me an error

And the error is?

Our crystal balls are broken, we are not mind-readers, you need to give us the EXACT error you are getting.

If'n that is ALL of your code I can make an informed guess what at least one of the errors might be, but we should wait for you to tell us.
L64,72: You're missing break statements unless you intended to fall through to the next case. That won't give you an error, but will definitely give you the wrong answer.

As Furry Guy said, we need to know the exact error message.
The error might be that "Numbersin.txt" and/or "Revised Numbers.txt" cannot be opened. If so the reason is that they are not where the program expect them. Try an absolute path in that case.
Do you mean this:

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
#include <iostream>
#include <fstream>

using namespace std;

int main() {
	ifstream NumbersIn("Numbersin.txt");
	ofstream RevisedNumbers("Revised Numbers.txt");

	if (!NumbersIn || !RevisedNumbers)
		return (cout << "Cannot open files\n"), 1;

	int s{ 2 }, a{}, b{};

	for (int Numin{}; NumbersIn >> Numin; ) {
		if (Numin < 0)
			Numin = -1;
		else if (Numin > 0)
			Numin = 1;
		else
			Numin = 0;

		RevisedNumbers << Numin << '\n';

		switch (Numin) {
		case -1:
			a += s;
			break;

		case 1:
			b += s;
			break;

		case 0:
			++s;
			break;
		}
	}

	cout << "a=" << a << "b=" << b << "s= " << s << '\n';
}

Topic archived. No new replies allowed.