C++ toupper help!

Boogieboo6

@realDonaldTrump
OP
Member
Joined
Jul 30, 2015
Messages
965
Trophies
1
Age
23
XP
807
Country
United States
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!
 

Logan Pockrus

Knawledge is key.
Member
Joined
Jan 1, 2016
Messages
1,338
Trophies
0
XP
1,062
Country
United States
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

0x40

Well-Known Member
Member
Joined
Apr 20, 2013
Messages
281
Trophies
1
Location
/
XP
807
Country
United States
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.
 

Issac

Iᔕᔕᗩᑕ
Supervisor
Joined
Apr 10, 2004
Messages
7,025
Trophies
3
Location
Sweden
XP
7,346
Country
Sweden
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,

grossaffe

Well-Known Member
Member
Joined
May 5, 2013
Messages
3,007
Trophies
0
XP
2,799
Country
United States
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.
 

0x40

Well-Known Member
Member
Joined
Apr 20, 2013
Messages
281
Trophies
1
Location
/
XP
807
Country
United States
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?
 

Boogieboo6

@realDonaldTrump
OP
Member
Joined
Jul 30, 2015
Messages
965
Trophies
1
Age
23
XP
807
Country
United States
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,

0x40

Well-Known Member
Member
Joined
Apr 20, 2013
Messages
281
Trophies
1
Location
/
XP
807
Country
United States
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.
 

grossaffe

Well-Known Member
Member
Joined
May 5, 2013
Messages
3,007
Trophies
0
XP
2,799
Country
United States
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.
 

Boogieboo6

@realDonaldTrump
OP
Member
Joined
Jul 30, 2015
Messages
965
Trophies
1
Age
23
XP
807
Country
United States
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!
 

Boogieboo6

@realDonaldTrump
OP
Member
Joined
Jul 30, 2015
Messages
965
Trophies
1
Age
23
XP
807
Country
United States
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!
 

Scarlet

Onion Soup
Editorial Team
GBAtemp Patron
Joined
Jan 7, 2015
Messages
5,145
Trophies
2
Location
Middleish North-Right
Website
scarlet.works
XP
14,772
Country
United Kingdom
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

0x40

Well-Known Member
Member
Joined
Apr 20, 2013
Messages
281
Trophies
1
Location
/
XP
807
Country
United States
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

Cyan

GBATemp's lurking knight
Former Staff
Joined
Oct 27, 2002
Messages
23,749
Trophies
4
Age
45
Location
Engine room, learning
XP
15,649
Country
France
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

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: https://www.ebay.com/itm/386617469929?mkcid=16&mkevt=1&mkrid=711-127632-2357-0&ssspo=2T8UwYf_Qse&...