d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Just Like Everyone Else > Need C++ Help
Prev12
Add Reply New Topic New Poll
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
May 30 2014 04:47am
Quote (MnG @ 30 May 2014 04:08)
Not sure about KrzaQ2's post  :wacko: .
It's simple: you make an assumption you have no right to make.
Member
Posts: 654
Joined: Jun 19 2007
Gold: 135.00
May 31 2014 05:54pm
Quote (carteblanche @ May 29 2014 11:39pm)
perhaps two variables instead of variable + constant would help you?

Code

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

y = 1

Code

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

x = 0

tell me what you think x and y are for each code snippet.

Reading from right to left answer is flipped, why wouldn't they make it the same as math/reading? lol
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
May 31 2014 08:46pm
Quote (MnG @ May 31 2014 07:54pm)
Reading from right to left answer is flipped, why wouldn't they make it the same as math/reading?  lol


in all my years of watching newbies learn to program, a lot of people are annoyed by the single equal sign to denote assignment, which is understandable. the idea that x = y is not the same as y = x is confusing as hell. some languages like smalltalk use := instead of just =. but you're the only one complaining about direction.

if it makes it easier for you to read left to right, instead of thinking of x = 1 as "put 1 into x" you should read it as "set x equal to 1". not every language uses this direction. COBOL and R come to mind as reversing it.
Member
Posts: 14,861
Joined: Jun 28 2007
Gold: 35,165.53
Aug 2 2014 07:57pm
I liked this, currently learning C++ myself and I'm in chapter 3 of C++ Primer (On arrays, not fun) but I wanted to give this a try because it uses a function from the chapter. So I came up with this.

Code
char c;

void main()
{
cout << "Please type a letter, and I will tell you if it is a capital or a lower-case letter: ";
while (cin >> c)
{
if (isupper(c))
{
cout << c << " is capital letter." << endl;
}
else
{
cout << c << " is a lowercase letter." << endl;
}
}
}


Same concept but on a string

Code
string input;
int cap_count, low_count;

void main()
{
cout << "Type a sentence and I will tell you how many capital letters and lowercase are in it: " << endl;
while (getline(cin, input))
{
for (auto c : input)
{
if (isupper(c))
{
++cap_count;
}
else if (islower(c) && !isspace(c))
{
++low_count;
}
}
cout << cap_count << " capital letters and " << low_count << " lowercase letters." << endl;
cap_count -= cap_count;
low_count -= low_count;
}
}


This post was edited by InunoTaishou on Aug 2 2014 08:02pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Aug 2 2014 09:46pm
Good job at necroing a dead post lol...
Member
Posts: 17,908
Joined: Jan 24 2006
Gold: 48.00
Sep 10 2014 02:27am
Quote (AbDuCt @ Aug 2 2014 11:46pm)
Good job at necroing a dead post lol...


In all fairness, it was probably still on the first page... He may not have known.
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Sep 10 2014 02:44am
One would assume that people learn to read dates somewhere in the elementary school.
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll