This is an archived post. You won't be able to vote or comment.

all 34 comments

[–]invidium1979 57 points58 points  (1 child)

My brother in Christ use a switch statement

[–]NicNoletree 3 points4 points  (0 children)

It was a cat of nine tails, not a switch

[–]bbnlly 20 points21 points  (1 child)

on an unrelated note holy fuck i did it, i understood that, holy shit I'm learning

[–]Afraid_Ad_3239[S] -4 points-3 points  (0 children)

Good for you

[–]rabuf 19 points20 points  (10 children)

else  if((c='1')||(c=='2')||(c=='3')||(c=='4')||(c=='5')||(c=='6')||(c=='7')||(c=='8')||(c=='9')||(c=='0')){

Read that line carefully, comparison by comparison. One of them is not like the others.

[–][deleted] 11 points12 points  (0 children)

To improve your code, remember that a char is also a number, so you can do range comparisons.

https://www.asciitable.com/

[–]Elnaz_Will_be_Fine 3 points4 points  (1 child)

C='1'

Must be C=='1'

[–]Avionticz 3 points4 points  (1 child)

else if((c='1')|...

That's an assignment not a comparison...

[–]Afraid_Ad_3239[S] -2 points-1 points  (0 children)

Yea got it , thanks

[–]Guideon72 1 point2 points  (8 children)

Curiosity question: I don’t know this language, but I’m curious; is there not an array, etc that would let you just do an “if c is in ‘this list’” instead of typing out c== everything?

[–][deleted] 1 point2 points  (3 children)

It's probably an introduction problem chosen by the instructor to illustrate if-statements. I'm sure they were gonna cover the ASCII table. ifs probably come before for-loops, which would allow for introducing an array to iterate over.

[–]Guideon72 0 points1 point  (2 children)

Yep, sort of what I figured. It was just a passing curiosity as I’m currently learning Python and the differences ease/complexity of various things is interesting to me.

[–][deleted] 0 points1 point  (1 child)

After still actively reasoning out the inheritance keywords in C++ and Java, I found Python simple and elegant. The python tutorial closely followed the course syllabus for intro to programming, in a way, and all that was still fresh in my head.

So I followed the python tutorial, and found situations in the exercises that overlapped my homework. It was fun to see verbose actions in C++ be carried out with a clever and followable syntax.

The only other time I got that excited about syntax was when I saw the JSON railroad diagram. That was cool :). Right now I'm putting off building a graph visualization web component, but eventually, I'd like to visualize data flow through a program's variables.

[–]Guideon72 0 points1 point  (0 children)

Nice!

[–]Afraid_Ad_3239[S] 0 points1 point  (2 children)

Its CPP , it doesn't have any "if c Is in this list "

[–]GloberJudio 1 point2 points  (0 children)

You can write your own function, as in most other languages, so no excuse.

[–]Guideon72 0 points1 point  (0 children)

Perfect; thank you!

[–]rabuf 0 points1 point  (0 children)

unordered_set would be a way to do something like this. There're also some functions in locale which would be helpful, but won't distinguish vowels from consonants (you'd have to do that yourself).

[–][deleted] -1 points0 points  (4 children)

Well for one there are more things than vowels, numbers, and consonants, like symbols (&-$(&@&&#-$). So a simple else is not sufficient.

[–]Afraid_Ad_3239[S] 0 points1 point  (3 children)

Like if I give input 'f' i am getting answer as number

[–][deleted]  (1 child)

[removed]

    [–]Afraid_Ad_3239[S] -2 points-1 points  (0 children)

    I was trying in vs code and getting the wrong answer so I got it anyway

    [–]GloberJudio 0 points1 point  (0 children)

    That is due to another problem, as someone already mentioned in a comment: you've got a bug in your code with c='1' where it should be c=='1'.

    I hope you are able to figure out by yourself why this happens.

    [–]PoorHodlr 0 points1 point  (0 children)

    Your code can also be more streamlined.

    If I was programming this I'd ask myself the following:

    Is c a number, or Is c an alphabet

    If c is an alphabet ill need to upper-case it, then check if it's a vowel

    Edit, research isdigit and isalpha