Which one is Curent and Previous number ?

Hello Hello ! Help me with this please, is a noob thing:
I am working on a function which return 1(true) if a int number is in ascending order.
For exemple:
--> 67 return 1;
--> 76 return 0;
--> 6 return 1;
--> 66 it is return what I want...i put it now to to return 1;

My question to you guys is, which one is Previous Number and Current number?
I solved the function , but I wanted to understand the code better.

SO i type 67 ,which one is Current,Previous Number.
I thought 6 is previous and 7 is curent...but is not working that well in code.

Which one is ?
Last edited on
Your question makes no sense without seeing the code, and the context in which those terms are used.

If you wrote your own code, how come you don't understand it?
the code was given to me from a book !
Is really that hard ?

In programming, which one si considered previous number and current number.?
for exemple 56, which one is previous , and which one is current number/ figure.

Is 5-previous and 6-current ?

I dont know,that why I ask here.

Sorry for me english !
oh, it's an English question? :) "previous" is just a relative term. If you're discussing natural numbers, that is: 1,2,3,4,5 ... , then if discussing 4, 3 is the previous number in the series.

Your context is likely digits. If my number was 987654, I could split it up into array indices to help solve the problem, so it's clear: [9, 8, 7, 6, 5, 4]. There is clearly an order here. Looking at "6", the previous number is 7 and the next number is 5.
I wrote a little function to solve it as well by examining digits from right to left with the help of our friendly modulus and integer division operators. I did end up making a variable called cur or the current digit that I compare to the "last" one (digit to the right, in my case). Since I annihilate the number with each iteration of the loop, I felt last was more appropriate than something like 'next' or 'previous'. Hope that helps in your understanding of these relative words. Really, they're more like implementation details to help progress the logic.

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

using namespace std;

// True if each subsequent digit is >= previous digit
bool DigitsAscending(int n)
{
    int last = n%10;
    int cur;
    while (n /= 10)
    {
        cur = n%10;
        if (cur>last)
            return false;
        last = cur;
    }
    return true;
}

int main() 
{
    vector<int> examples = 
    {
        123,
        112233,
        9875,
        1479,
        6666,
        102,
        1
    };

    cout << boolalpha;
    for (auto& e : examples)
        cout << setw(8) << e << " => " << DigitsAscending(e) << endl;

    return 0;
}

     123 => true
  112233 => true
    9875 => false
    1479 => true
    6666 => true
     102 => false
       1 => true
yea thanks a lot.
thanks a lot man...Wish you best. I start doing this for serious...till now I was play too much Call of Duty..........Bless you man.
thanks a lot man...Wish you best. I start doing this for serious...till now I was play too much Call of Duty..........Bless you man. !!!!!!!!!!
Topic archived. No new replies allowed.