Don't know where im doin the problem.

Hey guys.

I'm technically done with this code but there is a error in the answers.
5 9 ( for () function)

The answers
5678
6789
7890
8901
9012

Getting them is easy. Add +1 every second number.
If the number is more than 10 it shoud make the number itself zero and add +1 on the zero.

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

using namespace std;
//---------------------------------------
int main ()
{
    int sk1, sk2, sk3, sk4, a, b, i;

    sk1 = 0; sk2 = 0; sk3 = 0; sk4 = 0;
    cout << " A ir B" << endl;
    cin >> a >> b;
    for ( int i = a; i <= b; i++)
    {

        if ( a == 10) a = 0;
        sk1 = a ;
        if ( sk1 == 10) sk1 = 0;
        sk2 = sk1 + 1;
        if ( sk2 == 10) sk2 = 0;
        sk3 = sk2 + 1;
        if ( sk3 == 10) sk3 = 0;
        sk4 = sk3 + 1;

        a = a + 1;
       cout << sk1 << sk2 << sk3 << sk4  << endl;
    }

    return 0;
}


The answers I get is:
5678
6789
78910
8901
9012
Last edited on
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
#include <iostream>

using namespace std;

int main ()
{
    int sk1, sk2, sk3, sk4, a, b;
    
    sk1 = 0; sk2 = 0; sk3 = 0; sk4 = 0;
    cout << " A ir B" << endl;
    cin >> a >> b;
    for ( int i = a; i <= b; i++)
    {
        if ( a == 10) a = 0;
        sk1 = a ;
        if ( sk1 == 10) sk1 = 0;
        sk2 = sk1 + 1;
        if ( sk2 == 10) sk2 = 0;
        sk3 = sk2 + 1;
        if ( sk3 == 10) sk3 = 0;
        sk4 = (sk3 + 1)%10;
        
        a = a + 1;
        cout << sk1 << sk2 << sk3 << sk4  << endl;
    }
    
    return 0;
}



 A ir B
1 20
1234
2345
3456
4567
5678
6789
7890
8901
9012
0123
1234
2345
3456
4567
5678
6789
7890
8901
9012
0123
Program ended with exit code: 0


A ir B
5 9
5678
6789
7890
8901
9012
Program ended with exit code: 0
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

int main() {
	constexpr unsigned NoSeq {4};
	unsigned a {}, b {};

	std::cout << "Range a - b: ";
	std::cin >> a >> b;

	if (a > b)
		return (std::cout << "Invalid range\n"), 1;

	for (; a <= b; ++a) {
		for (auto i {a}; i < a + NoSeq; ++i)
			std::cout << i % 10;

		std::cout << '\n';
	}
}



Range a - b: 5 9
5678
6789
7890
8901
9012

Thanks you guys a lot <3
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>
using namespace std;

int main ()
{
   string digits = "0123456789012";
   int a, b;
   cout << "Input a and b: ";
   cin >> a >> b;
   for ( ; a <= b; a++ ) cout << digits.substr( a % 10, 4 ) << '\n';
}


Input a and b: 5 9
5678
6789
7890
8901
9012
Last edited on
Topic archived. No new replies allowed.