Keeping track of the gap between two numbers that were input

Using simple while loops/if statements (i'm new) how do i ask the user for multiple inputs and then calculate the difference between those inputs?
- The inputs are like this (a b)
-The catch is once the user inputs 99 99, the loop of asking questions for inputs stops. and if the user inputs anything below 0 or greater than 24 for a ,or below 0 or greater than 60 for b the program should discard that data.
- I've tried having 4 variables (a&b and c&d) but I couldn't do it without multiple while loops therefore making it harder to exit when user inputs 99 99
- I've tried converting a and b to the new variable c and d (as shown below) but that doesn't discard any useless data properly.

You can ignore all variables except a,b,c,d. The other variables are for statistical purposes. Also I know the program itself isn't complete but I can't do anything else until I fix this algorithm
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

//Variable Declaration
int a; //1st hour time entered
int c; //2nd hour time entered
int b; //1st minute time entered
int d; //2nd minute time entered
int z = 0; //invalid entries
int y = 0; //valid entries
int x = 0; //number of back2back pairs
int m = 0; //if m = 0 no data on gap times will be released
int n; //gap time
double o = 0; //total gaps
double p; //average gaps


//enter time
cout<<"Enter 24hr time (99 99 to exit): ";
cin>>a>>b;

 
//loops question until 99 99 entered    
while ((a != 99 && b != 99)){
     //if time is invalid
     
    if (a < 0 || b < 0 || a >= 24 || b >= 60 ){
        cout<<"INVALID TIME"<<endl;
        z = z + 1;
        cout<<"Enter 24hr time (99 99 to exit): ";
        cin>>a>>b;
    }
    else{
        y = y + 1;
        a = c;
        b = d;
        //enter time
        cout<<"Enter 24hr time (99 99 to exit): ";
        cin>>a>>b;
        
        if (a < 0 || b < 0 || (a >= 24 && a != 99 && b != 99) || (b >= 60 && a != 99 && b != 99)){
            cout<<"INVALID TIME"<<endl;
            z = z + 1;
            cout<<"Enter 24hr time (99 99 to exit): ";
            cin>>a>>b;
        }
        else {
            //math
            m = m + 1;
            x = x + 1;
            n = (a*60+b) - (c*60+d);
            if (n < 0){
                n = 24*60+n;
            }
            o = o + n;
        }
    }
    
}


edit: Example: 1-2-3-4-5 if those are the 5 numbers. I want the difference between 5 to 4, 4 to 3, 3 to 2, 2 to 1 and so on.

Not the difference between 2and 1, 4 and 3 etc.
Last edited on
Topic archived. No new replies allowed.