d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Just Like Everyone Else > Need C++ Help
12Next
Add Reply New Topic New Poll
Member
Posts: 10,237
Joined: Aug 6 2006
Gold: 157.71
Feb 26 2014 06:48pm
The object of this program is to determine whether the user's input is a capital or lowercase using if/else

Here's what I've come up with so far.
Any help is great help.
Code
#include <iostream>
int main()
{
using namespace std;
char input;
cout << "Please type a letter, and I will tell you if it is a capital or a lower-case letter: ";
cin >> input;
if (input >= '97' <= '122') {
cout << "The letter is lowercase"
or cout << "The letter is uppercase";
}
return 0;
}
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Feb 26 2014 06:51pm
your first problem:

http://www.cplusplus.com/doc/tutorial/operators/

scroll down to logical operators.

second problem:

http://www.cprogramming.com/tutorial/lesson2.html
Member
Posts: 10,237
Joined: Aug 6 2006
Gold: 157.71
Feb 26 2014 06:57pm
Quote (carteblanche @ 26 Feb 2014 19:51)
your first problem:

http://www.cplusplus.com/doc/tutorial/operators/

scroll down to logical operators.

second problem:

http://www.cprogramming.com/tutorial/lesson2.html


You're my hero <3 if I had fg I'd donate to you.
Member
Posts: 654
Joined: Jun 19 2007
Gold: 135.00
May 29 2014 06:50am
//Taken from http://www.cplusplus.com/doc/tutorial/operators/

Assignment operator (=)
The assignment operator assigns a value to a variable.
x = 5;
This statement assigns the integer value 5 to the variable x. The assignment operation always takes place from right to left, and never the other way around

//The above seems very confusing to me, I read x = 5; as x is now 5 not 5 is now x
//When the site says never the other way around what does it mean? I read left to right and it seems to give the same result (including the examples they give).
//Can someone post an example showing what they mean by you read it right to left? It looks the same to me :blink:
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
May 29 2014 08:22am
Quote (MnG @ May 29 2014 07:50am)
//Taken from http://www.cplusplus.com/doc/tutorial/operators/

Assignment operator (=)
The assignment operator assigns a value to a variable.
x = 5;
This statement assigns the integer value 5 to the variable x. The assignment operation always takes place from right to left, and never the other way around

//The above seems very confusing to me, I read x = 5; as x is now 5 not 5 is now x
//When the site says never the other way around what does it mean?  I read left to right and it seems to give the same result (including the examples they give).
//Can someone post an example showing what they mean by you read it right to left?  It looks the same to me  :blink:


In mathematical equations typically you read it from left to right

Code
2x + 5 = 15


You would be surprised how many newbies seem to want to do assignment operations the same way

Code
5 = x;


Thus the need to differentiate.

Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
May 29 2014 12:03pm
The C++ standard does not guarantee that ASCII is used for character values. So instead of comparing to 97/122 you should use 'a' and 'z'. But! The standard doesn't guarantee that any characters besides '0'-'9' are contiguous or ordered. That's why you should use std::isupper function ( http://en.cppreference.com/w/cpp/string/byte/isupper ).
Member
Posts: 654
Joined: Jun 19 2007
Gold: 135.00
May 29 2014 08:08pm
Quote (Minkomonster @ May 29 2014 08:22am)
In mathematical equations typically you read it from left to right

Code
2x + 5 = 15


You would be surprised how many newbies seem to want to do assignment operations the same way

Code
5 = x;


Thus the need to differentiate.


Still ends up with the same value for x though right? Do you have an example of where it would change? I don't see how it's any different than algebra.

Not sure about KrzaQ2's post :wacko: .
Member
Posts: 29,614
Joined: Sep 23 2008
Gold: 0.00
May 29 2014 08:26pm
Quote (Minkomonster @ May 29 2014 09:22am)
In mathematical equations typically you read it from left to right

Code
2x + 5 = 15


You would be surprised how many newbies seem to want to do assignment operations the same way

Code
5 = x;


Thus the need to differentiate.


Even with the notion of reading mathematical equations from left to right,

Code
x = 5;


reads as "x is equal to 5" or "x equals 5", which means the value of x is equal to 5.

It amuses me how many people get that mixed up.
Member
Posts: 654
Joined: Jun 19 2007
Gold: 135.00
May 29 2014 11:15pm
Which is what is confusing, when they say ALWAYS read from right to left, is it not the same exact thing?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
May 29 2014 11:39pm
Quote (MnG @ May 29 2014 08:50am)
//Taken from http://www.cplusplus.com/doc/tutorial/operators/

Assignment operator (=)
The assignment operator assigns a value to a variable.
x = 5;
This statement assigns the integer value 5 to the variable x. The assignment operation always takes place from right to left, and never the other way around

//The above seems very confusing to me, I read x = 5; as x is now 5 not 5 is now x
//When the site says never the other way around what does it mean?  I read left to right and it seems to give the same result (including the examples they give).
//Can someone post an example showing what they mean by you read it right to left?  It looks the same to me  :blink:


Quote (MnG @ May 30 2014 01:15am)
Which is what is confusing, when they say ALWAYS read from right to left, is it not the same exact thing?


perhaps two variables instead of variable + constant would help you?

Code

int y = 0;
int x = 1;
y = x;


Code

int y = 0;
int x = 1;
x = y;


tell me what you think x and y are for each code snippet.
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll