Ask coding questions

← Back to all posts
While Loop
WILLIAMMACDONAL

An ascending integer occurs when each digit is greater than any digit that precedes it. An example is
478. Write a program that finds the number of ascending integers between 200 and 300.

I know how to do basic while loops but cannot figure out how to separate a number and determine if it is an ascending integer.

C++.

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
AnthonyKeogh1
WILLIAMMACDONAL
Comments
hotnewtop
Coder100

So sorry about that, logic mistakes :(

If you need I can explain the code to you, but it should be pretty straightforward (I think)

WILLIAMMACDONAL

@Coder100 Thank you very much.

Coder100
realTronsi

@Coder100 here is better solution

Coder100

pls do std::endl @realTronsi

realTronsi

@Coder100 idk cpp meanie

Coder100

xd i mean its just user preference @realTronsi

realTronsi

@Coder100 fixed

Coder100

but the thing is std::endl is better because some people use \r\n so you could have just gotten garbled text jk jk most os now do that convert automatically @realTronsi

realTronsi

@Coder100 ok at edit your answer so it is the better version >:)

Coder100
Summit

@Coder100 its not rlly user preference cus realTronsi didnt use use namespace std so it wouldnt work if he/she didnt use std::endl

Summit

@realTronsi yes you do if you dont put mark it as standard library

Coder100

After thinking about this problem, I got to this solution.

thank god for 0!

Hmm there's an extraneous 300 in there, how strnage

realTronsi

@Coder100 he asked for number of, not the exact numbers (and your answer also doesn't work) but literally just 6+5+4+3+2+1 (21) is your answer

basic permutation as such:

23 ,4-9: 6 possibilities
24
,5-9: 5 possibilities,

etc.

Your script gave these numbers:

some such as 280 aren't ascending, and you also missed a few

Coder100

num.size() iirc @realTronsi

Coder100

yeah unfortunately i did a bad plz read the marked one @realTronsi

realTronsi

@Coder100 ok good. Just that your answer is questionable.

(not actual code since idk much cpp but there is no point in looping over every single number.)

Coder100

hey does it not work? @realTronsi

Coder100

it stores all the integers, and if I took the time to study permutations, it might be more elegant. @realTronsi

realTronsi

@Coder100 yours work but it's a lazy solution lol

Coder100

Something like:
32 8! * 7!
should suffice but it doesn't i don't think
@realTronsi

realTronsi

@Coder100 did you see my code answer though? If you put that in cpp syntax it should work, I could put it in js syntax to prove a point

Coder100

indeed plz helpz makez betterz @realTronsi

Coder100

OH RIGHT i should probably skip a few numbers yes yes @realTronsi

realTronsi

@Coder100

This extremely short chunk of code in js works, (just an extra 9 at the end that can easily be solved)

Coder100

hmm true, but whats with the 9 anyways @realTronsi

realTronsi

@Coder100 idk its nodejs problem, try putting a console.log() after the while loops and the 9 disappears

realTronsi

@Coder100 ill convert it into cpp

Coder100

c++ god @realTronsi

realTronsi

@Coder100

there might be syntax errors since im not the best cpp

realTronsi

@Coder100

theres an error unqualifed-id idk how to fix but anyways theres code

Coder100

hol' up why is there an extra << @realTronsi

realTronsi

@Coder100 thats an old version dont look at it

Coder100

what lang?

WILLIAMMACDONAL
Coder100
Coder100

please read the question thanks @RYANTADIPARTHI

Coder100

btw your example won't work endl isn't defined @RYANTADIPARTHI

Coder100

actually read the question smh smh @RYANTADIPARTHI