Math adds up but function does not work correctly

Code works with first 4 digit and passcode but does not if im trying to get second 4 digit.

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
 #include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <fstream>
#pragma warning(disable : 4996)

using namespace std;










 string findUser(ifstream& myfile) {
	string cardUN, securityUN, cardN, securityN;
	int k = 0;
	int cardNumberLine;

	cout << "Please put last 4 digits of you credit card: ";
	cin >> cardUN;


		for (int l = 0; l < 21; l + 7) {

			getline(myfile, cardN);
			if (cardN == cardUN) {
				k++;
				cardNumberLine = l;
				break;

			}

		}

		if (k == 0) {
			cout << "Invalid card number.";
			return "0";
		}

		cout << "Please input the secutity code: ";
		cin >> securityUN;

		securityN = getLine(myfile, cardNumberLine++);

		if (securityN != securityUN) {
			cout << "ACCESS DENIED!";
			return "0";
		}

	
	
}


int main() {
	
	ifstream myfile("applecarddata.txt");
	myfile.is_open();
findUser(myfile);

	myfile.close();







TXT file lookls like this:
1234
111
Patrik Star
05
20
500

1235
112
James Jack
01
19
250

1236
113
Rob Robinson
01
18
550
Last edited on
for (int l = 0; l < 21; l + 7)

that maybe should be += 7 ?! what you have *does not do anything*.

your data and code have too many random numbers for me to invest in unscrambling what else may not be right in there. what is 21? what is 7? what is 112 in the file mean?

are you trying to skip lines in the file that are unimportant? If so, I don't think you did that right.
Last edited on
It just has to verify 4 digit with security code and yeah it does not do anything after it.
I am trying to skip lines, 21 is total number of lines, 7 is every 7th line is the same type of information
1234, 1235, 1236 are 4 digits that has to verify with security code which are 111 112 113 relatably
Last edited on
you need to actually read each line, even if you don't use it, for text files. binary files can skip junk, text files cannot so easily.

you want to read the line, that is security code, does it match, if not its not your guy, read N lines until next security code, check that one ... until you find the guy or run out of file.
Try coding that pattern, see if it works. And again, watch that for-loop final statement: unless intending to do weirdness, you should modify the loop variable in the last statement(s). Its ok to not do that if you know what you intend: for(; condition; ) is fine so long as inside the loop, you either loop forever by design or modify something that triggers a break or the condition.... :) and some people even put all their code in the loop body for simple loops, also fine.
for(x = 0; x < 1000; cout << x++;); //intentional weirdness.
Last edited on
Registered users can post here. Sign in or register to post.