C++ toupper help!

  • Thread starter Thread starter Boogieboo6
  • Start date Start date
  • Views Views 2,846
  • Replies Replies 35
I just want to make sure you realize why yours didn't work :)
I do. I put the end parentheses in the wrong spot. It ended up reading like "Make variable == N uppercase and compare to N" rather than "Make variable uppercase THEN compare to N". Maybe it's not exactly like that and I'm just terrible at explaining, but I do understand why it was wrong. Thanks for checking!
 
Why are system("pause") and commenting //end if terrible coding habits?
"// end if" serves no other purpose than to get you in the habit of typing "end if"; you're probably doing that in preparation for #if statements, which are preprocessor (macro) "if" statements, and they require you to type #end if after every #if statement (sorry if that didn't make sense, I'm juggling so many threads right now).

"system("pause")" is fine, just know that it only works on windows.
 
  • Like
Reactions: Boogieboo6
Well that's... I guess this is supposed to be a "first foray into programming" class? I've got some reservations with this class


I'm gonna have to disagree with you there. The editor does not know if my intention is to add the code into the if statement or not, nor do I want it deciding for me what I want to do. I stick to the basics. I've used Netbeans and Eclipse in the past, which are decent IDEs. Done a bit of work in a generic text editor. But nowadays I work mostly in vim which certainly does not add brackets for me (maybe there's a plugin to do that, but I wouldn't want it).
If you're typing something at the same indentation level as the first one, then it wouldn't need to guess.
"// end if" serves no other purpose than to get you in the habit of typing "end if"; you're probably doing that in preparation for #if statements, which are preprocessor (macro) "if" statements, and they require you to type #end if after every #if statement (sorry if that didn't make sense, I'm juggling so many threads right now).

"system("pause")" is fine, just know that it only works on windows.
system("pause") is not fine on any system. Even on Windows it's a slow and hacky solution that runs any executable it finds called "pause" instead of always pausing.
 
I do. I put the end parentheses in the wrong spot. It ended up reading like "Make variable == N uppercase and compare to N" rather than "Make variable uppercase THEN compare to N". Maybe it's not exactly like that and I'm just terrible at explaining, but I do understand why it was wrong. Thanks for checking!
Yeah, close enough :)
Actually, You compare if the variable is equal to N. Which is either the boolean values True or False. Then you use toupper on that boolean value, which I suppose threw an error.

Edit:
If it didn't throw an error, it should have always been false.
if( *something that doesn't work = false* )
and many times, but I don't dare to say always, something that works will equal True.

if( toupper( 'n' ) ) would be true.
 
Last edited by Issac,
If you're typing something at the same indentation level as the first one, then it wouldn't need to guess.
What is this, python?

I am curious, though, what editor are you using that does this? I've never used an editor that automatically did stuff like that for me, and I know that kind of stuff would piss me off.
 
What is this, python?

I am curious, though, what editor are you using that does this? I've never used an editor that automatically did stuff like that for me, and I know that kind of stuff would piss me off.
Python? You don't indent your code in any other language when it's not required?
 
What is this, python?

I am curious, though, what editor are you using that does this? I've never used an editor that automatically did stuff like that for me, and I know that kind of stuff would piss me off.
When I type something like this
if (condition)
.....cout << "hello";
Visual Studio 2015 auto indents the cout statement. Also when doing this:
int main()
{
.....cout << "Hello";
}
It auto indents again :D
But GBATemp won't show a bunch of spaces :/
 
Last edited by Boogieboo6,
I do indent, but indentation is purely for the benefit of those looking at the code while in Python it actually affects scoping.
As long as you indent, I can't think of a scenario where inserting the brackets automatically would be a problem. Your argument against this feature kinda relies on the user not indenting their code, which is insane.
 
As long as you indent, I can't think of a scenario where inserting the brackets automatically would be a problem. Your argument against this feature kinda relies on the user not indenting their code, which is insane.
I don't like something editing my code for me. I was always perturbed by IDEs automatically giving me a closing parenthesis when I'd make an open one. I can reach that key myself, thank you, and I'll use it at the appropriate time.
 
Hello again! I'm having trouble on an assignment with questions 1, 6, and 8.
If an if statement's true path contains the statement double avg = 0.0;, where can the avg variable be used?
a. in any instruction after the declaration statement in the entire program (I think it's this one)
b. in any instruction after the declaration statement in the if statement
c. in any instruction after the declaration statement in the if statement's true path.
d. none of the above because you can't declare a variable in an if statement's true path
If an expression does not contain any parentheses, which of the following operators is performed first in the expression?
a. arithmetic (I think it's this one)
b. comparison
c. logical
d. you can't tell without seeing the expression
Which of the following compares the contents of an int variable named quantity with the number 5?
a. if (quantity = 5)
b. if (quantity == 5)
c. if (quantity is 5)
d. if (quantity =! 5) (I think it's this one)
Any help is appreciated. I put my guesses inside!
 
Instead of guessing, can't you just try them yourself and see what happens?
Yeah, but they were like educated guesses. Not just shots in the dark. I'm fairly certain I got them all right, but somebody else confirming them would be awesome!
 
Which of the following compares the contents of an int variable named quantity with the number 5?
a. if (quantity = 5)
b. if (quantity == 5)
c. if (quantity is 5)
d. if (quantity =! 5) (I think it's this one)
Just for curiosity's sake, did you copy 8 down exactly? Because technically, both B and D compare quantity to the value of 5. B checks if it is equal, and D checks if it isn't.

Edit: I'm an idiot.
!= is not equal to, not =!. But yeah, you got that one wrong lol
 
Last edited by Scarlet,
  • Like
Reactions: Boogieboo6
Yeah, but they were like educated guesses. Not just shots in the dark. I'm fairly certain I got them all right, but somebody else confirming them would be awesome!
You did not get all of them right. You should check your answers by actually testing them in code.
 
  • Like
Reactions: Boogieboo6
But GBATemp won't show a bunch of spaces :/
don't post your code directly in the message.
add either [ code ] your code here [/code] tag,

Code:
main() {

       .....
}

or even a dual [ spoiler][ code] your code here [/code][/spoiler] if it's too long
Code:
main() {

       .....
}

or you can try the [ pre] your code [/pre] tags too
main() {

.....
}
 

Site & Scene News

Popular threads in this forum