The program does not print results

Hello everyone,
I'm writing here coz I can't find how to find the main problem at my code.
The main thing is, that this program does not print "sk" (at fd >> sk;) and the whole "for" cycle to the .txt file.
Could someone tell me why is it so?

Thank you.

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
  #include <iostream>
#include <fstream>
using namespace std;
//--------------------------------------------------------------------
void Vampire(ofstream& fr,int sk, int a, int b, int c, int d);
// --------------------------------------------------------------------
int main()
{

    int a, b, c ,d; // digits of the number with 4 counts
    int sk;   // number (4 digits)

    ifstream fd("Duomenys.txt");
    ofstream fr("Rezultatissimo.txt");

    fr << "A program 'Vampire Counts' starts." << endl;
    fr << "The main number: "; fd >> sk;
        fr << "\nVampire counts: " <<endl;

 for (sk; sk <= 1250 ; sk++)
 {
    a = sk/1000;
    b = (sk/100)%10;
    c = (sk/10)%10;
    d = sk % 10;
     Vampire (fr,sk,a,b,c,d);
     Vampire (fr,sk,b,a,c,d);
     Vampire (fr,sk,a,b,d,c);
     Vampire (fr,sk,b,a,d,c);
     Vampire (fr,sk,a,c,b,d);
     Vampire (fr,sk,c,a,b,d);
     Vampire (fr,sk,a,c,d,b);
     Vampire (fr,sk,c,a,d,b);
     Vampire (fr,sk,a,d,b,c);
     Vampire (fr,sk,d,a,b,c);
     Vampire (fr,sk,a,d,c,b);
     Vampire (fr,sk,d,a,c,b);


 }
 fd.close();
    fr.close();
    cout << "Results are in the file Rezultatissimo.txt" <<endl;
    return 0;
}
//----------------------------------------------------
void Vampire(ofstream& fr,int sk, int a, int b, int c, int d)
{
if (sk == (a*10+b)*(c*10+d))
fr << sk << " = " << a << b << " * " << c << d <<endl;
}
//------------------------------------
Last edited on
What is a number that should be printed?
That "sk" at "Duomenys.txt" is 1234.
Oh, I see. fd >>sk is extracting the number from the file, you want something like:
1
2
3
fr << "The main number: ";
fd >> sk;
fr << sk << '\n';
Thanks, now it writes that sk at .txt file! However, that cycle "for" still doesn't print at .txt....
@immadogewow

I found that the first number to be printed was 1260, which is more than your ending number. I put the for loop to end at 9999.

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
// Vampire.cpp : main project file.

#include <iostream>
#include <fstream>

using namespace std;

//--------------------------------------------------------------------
void Vampire(ofstream& fr,int sk, int a, int b, int c, int d);
// --------------------------------------------------------------------

int main()
	{

	int a, b, c ,d; // digits of the number with 4 counts
	int sk;
	ifstream fd("Duomenys.txt");
	ofstream fr("Rezultatissimo.txt");

	fr << "A program 'Vampire Counts' starts." << endl;
	fr << "The main number: ";
	fd >> sk;
	fr << sk << endl;
	fr << "Vampire counts: " << endl;

	for (sk; sk <= 9999 ; sk++)  // Go from 10 to 2000
		{
		a = sk/1000;
		b = (sk/100)%10;
		c = (sk/10)%10;
		d = sk % 10;
		Vampire (fr,sk,a,b,c,d);
		Vampire (fr,sk,b,a,c,d);
		Vampire (fr,sk,a,b,d,c);
		Vampire (fr,sk,b,a,d,c);
		Vampire (fr,sk,a,c,b,d);
		Vampire (fr,sk,c,a,b,d);
		Vampire (fr,sk,a,c,d,b);
		Vampire (fr,sk,c,a,d,b);
		Vampire (fr,sk,a,d,b,c);
		Vampire (fr,sk,d,a,b,c);
		Vampire (fr,sk,a,d,c,b);
		Vampire (fr,sk,d,a,c,b);
		}
	fd.close();
	fr.close();
	cout << "Results are in the file Rezultatissimo.txt" <<endl;
	return 0;
	}

//----------------------------------------------------

void Vampire(ofstream& fr,int sk, int a, int b, int c, int d)
	{

	if (sk == (a*10+b)*(c*10+d))
		{
		fr << sk << " = ((" << a <<" * 10 ) + " << b << ") * ((" << c << " * 10 ) + " << d << ") or [ (" << (a*10+b ) << ") * (" << c*10+d << ") ]" << endl;
		cout << sk << " = ((" << a <<" * 10 ) + " << b << ") * ((" << c << " * 10 ) + " << d << ") or [ (" << (a*10+b ) << ") * (" << c*10+d << ") ]" << endl;
		}
	}

//------------------------------------ 
Last edited on
There isn't a number in your range that makes line 49 be true
Topic archived. No new replies allowed.