• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 08:34
CEST 14:34
KST 21:34
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6Code S RO8 Preview: herO, Zoun, Bunny, Classic7
Community News
Weekly Cups (June 23-29): Reynor in world title form?10FEL Cracov 2025 (July 27) - $8000 live event14Esports World Cup 2025 - Final Player Roster14Weekly Cups (June 16-22): Clem strikes back1Weekly Cups (June 9-15): herO doubles on GSL week4
StarCraft 2
General
Weekly Cups (June 23-29): Reynor in world title form? StarCraft Mass Recall: SC1 campaigns on SC2 thread The SCII GOAT: A statistical Evaluation How does the number of casters affect your enjoyment of esports? Esports World Cup 2025 - Final Player Roster
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event HomeStory Cup 27 (June 27-29) WardiTV Mondays SOOPer7s Showmatches 2025 $200 Biweekly - StarCraft Evolution League #1
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers [G] Darkgrid Layout
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ ASL20 Preliminary Maps BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest Unit and Spell Similarities
Tourneys
[Megathread] Daily Proleagues [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET The Casual Games of the Week Thread [BSL20] ProLeague LB Final - Saturday 20:00 CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Stop Killing Games - European Citizens Initiative Trading/Investing Thread Russo-Ukrainian War Thread
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread Korean Music Discussion
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
Game Sound vs. Music: The Im…
TrAiDoS
StarCraft improvement
iopq
Heero Yuy & the Tax…
KrillinFromwales
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 699 users

C++ revision help! - Page 4

Blogs > konadora
Post a Reply
Prev 1 2 3 4 5 6 7 Next All
konadora *
Profile Blog Joined February 2009
Singapore66156 Posts
Last Edited: 2009-06-29 01:01:49
June 29 2009 00:40 GMT
#61
On June 29 2009 02:35 Scorch wrote:
Looks like you are trying to teach yourself programming from scratch without any guidance. That's hard. You should look for a C++ tutorial which explains the basics in an understandable and structured manner. Posing random questions on a very specific problem without quite understanding the answers won't help you much. Especially since those who give advice often look at the problem from a higher level that you don't even need yet. For example, I've seen people talk about compiler settings here, which isn't what you want to know at all and will only confuse you.
You won't make it far without knowing basic concepts like control structures, data types, return values etc. So you should try and learn those basics and then come back if any questions remain. Also, it's far easier for a beginner to modify and extend existing code than to write it yourself.

I understand that myself, but I haven't really been taught all the reasoning and concepts, and for my test, I'll have to write a code myself.

Lol I've managed to push my test to wednesday, woot
POGGERS
fusionsdf
Profile Blog Joined June 2006
Canada15390 Posts
June 29 2009 04:08 GMT
#62
On June 29 2009 08:19 virLudens wrote:
Show nested quote +
On June 29 2009 05:53 fusionsdf wrote:
On June 29 2009 01:41 konadora wrote:
Also, if you specify 'C' but the user types in 'c' instead (small C), then does it matter? I recall my teacher saying that caps matter a lot in programming.


since nobody answered this: yes, case matter Variable is different from VARIABLE and vArIaBlE. Generally constants are in all CAPS, normal variables are lowercase with either underscores between words like_this_variable or camel case likeThisVariable. Struct and Class names tend to have the first letter capitalized.

Its really important to stay consistent throughout your code.


camel notation ftw. there's also another one that has the type in the variable name, but it's fallen out of favour.


Hungarian Notation. I've always disliked it
SKT_Best: "I actually chose Protoss because it was so hard for me to defeat Protoss as a Terran. When I first started Brood War, my main race was Terran."
Cambium
Profile Blog Joined June 2004
United States16368 Posts
June 29 2009 05:52 GMT
#63
On June 29 2009 13:08 fusionsdf wrote:
Show nested quote +
On June 29 2009 08:19 virLudens wrote:
On June 29 2009 05:53 fusionsdf wrote:
On June 29 2009 01:41 konadora wrote:
Also, if you specify 'C' but the user types in 'c' instead (small C), then does it matter? I recall my teacher saying that caps matter a lot in programming.


since nobody answered this: yes, case matter Variable is different from VARIABLE and vArIaBlE. Generally constants are in all CAPS, normal variables are lowercase with either underscores between words like_this_variable or camel case likeThisVariable. Struct and Class names tend to have the first letter capitalized.

Its really important to stay consistent throughout your code.


camel notation ftw. there's also another one that has the type in the variable name, but it's fallen out of favour.


Hungarian Notation. I've always disliked it


Oh cool, I didn't even know it was called the Camel notation. I started with Hungarian Notation, and it's ultra lame
When you want something, all the universe conspires in helping you to achieve it.
Bill307
Profile Blog Joined October 2002
Canada9103 Posts
June 29 2009 07:44 GMT
#64
I feel like giving a lesson on data type basics.


8 bits = 1 byte, by the way. If you don't already know this, then repeat this to yourself 10 times, because I will interchange between bits and bytes constantly. E.g. if I say "32 bits" and then "4 bytes" then you need to recognize instantly that I'm talking about the same amount.


When you declare a variable, your compiler will set aside some region in memory (the computer's RAM) for that variable. Whenever you use that variable, you are accessing or modifying that region.

byte and char are both 8-bit (1-byte) variables: they occupy 8 bits in memory. Although they have different uses, in memory they look the same. E.g. the byte 65 and the char 'A' look exactly the same in memory: 65.

int and long are 16-bit and 32-bit variables, respectively. They store #s as integers. They can store both positive and negative integers. In memory, the int 65 might look like this: 0 65. Notice it occupies 2 bytes. Similarly, the long 65 might look like this: 0 0 0 65. If the number is too big to be stored in a single byte, then it spills over into the next byte, allowing you to store larger numbers.

Think of it like base-10 digits. A single digit can store only the numbers 0 to 9. Anything higher than 9 and you need 2 or more digits. Same thing with bytes, except it's base-256. You can store 0-255 in a single byte: anything higher than 255 and you need 2 or more bytes.

Base-10 example, counting from 8 to 12:
0 8
0 9
1 0
1 1
1 2

Base-256 (bytes) example, counting from 254 to 258:
0 254
0 255
1 0
1 1
1 2

If you can't figure out the pattern here, then look up number systems with different bases.

int and long can store negative numbers, too, but that's a lesson for another day. (It's actually pretty simple, if you understand binary and if it's explained correctly.)

If you're wondering what happens when you try to store a number that's too large in a byte, int, or long, then try it for yourself and see what happens (don't worry, it won't break anything).

float and double are 32-bit and 64-bit variables, respectively. These store numbers in floating point format, which is basically scientific notation. At this point in time, you might as well use doubles. But if you were to make, say, a game, where speed can be important, then you would use only floats in your program.


Pointers, when you start to use them (and die by them), take up 32 bits in memory. They're used to point to some location in memory, like where a variable is stored. Don't even try to learn how to use these until you understand a lot of simpler concepts first.

Structs and Classes take up varying amounts of memory, depending on what data they contain.


Hopefully now you understand variables a bit better.
Smix *
Profile Blog Joined January 2009
United States4549 Posts
June 29 2009 07:56 GMT
#65
Good luck on your exam kona
TranslatorBe an Optimist Prime, Not a Negatron // twitter @smixity
Superbia
Profile Blog Joined April 2008
Netherlands8889 Posts
June 29 2009 08:37 GMT
#66
On June 29 2009 16:44 Bill307 wrote:
int and long are 16-bit and 32-bit variables, respectively.


The size of int is actually compiler specific; on 32+ bit machines, int is usually 32 bit, which is what I think applies to konadora.
Minimal effort.
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
June 29 2009 08:41 GMT
#67
Bill your sizes are usually true on 16 Bit systems. On 32 Bit systems int is usually 32 bit. And the C++ standard promises even less.
On 32 Bit VS afaik byte/char=8bit, short=16bit, int/long=32 bit, long long=64 Bit. And of course each of them is available as signed and unsigned.
LiquipediaOne eye to kill. Two eyes to live.
konadora *
Profile Blog Joined February 2009
Singapore66156 Posts
June 29 2009 15:36 GMT
#68
Does it matter if I'm using a 64-bit edition of Vista?

Thanks a lot Bill, understand much clearer now, teacher hardly explained >__<

Thanks Smix
POGGERS
Bill307
Profile Blog Joined October 2002
Canada9103 Posts
June 29 2009 18:54 GMT
#69
Oh, thanks for the correction, guys.

So I guess the corrected version is:

short = 16-bit integer (-32768 to +32767)
long = 32-bit integer (approx. -2 billion to +2 billion)
int = 16- or 32-bit integer

Bah.

Well, I guess it's safest to assume int is only 16 bits, and use "long" if you need more than that.
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
June 30 2009 07:20 GMT
#70
From the Stroustrup:
Sizes of C++ objects are expressed in terms of multiples of the size of a char , so by definition
the size of a char is 1 . The size of an object or type can be obtained using the sizeof operator. This is what is guaranteed about sizes of fundamental types:
1 = sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
1 <= sizeof(bool) <= sizeof(long)
sizeof(char) <= sizeof(wchar_t) <= sizeof(long)
sizeof(float) <= sizeof(double) <= sizeof(long double)
sizeof(N) = sizeof(signed N) = sizeof(unsigned N)
where N can be char , shortint , int , or longint . In addition, it is guaranteed that a char has at least
8 bits, a short at least 16 bits, and a long at least 32 bits. A char can hold a character of the
machine’s character set.

Usual are:
char=8bit
short=16bit
int=16 or 32 bit
long=32 or 64 bit
long long=64 bit

There are also some typedefs with fixed size, but I forgot their names.
If I recall correctly there are also some size requirenments for pointers in relation to ints, but I forgot that too. On Win32 it is guaranteed that int,long are 32bit.
LiquipediaOne eye to kill. Two eyes to live.
konadora *
Profile Blog Joined February 2009
Singapore66156 Posts
Last Edited: 2009-07-09 16:03:44
July 09 2009 15:59 GMT
#71
Bump

I've been doing something called the BMI test, here's my program:

#include <iostream>
using namespace std;

int main()
{
double w, h;
double a;
cout << "Please enter your weight (in KG) and height (in meters)." << endl;
cin >> w >> h;
a = (w/(h*h));
if (w > 0, h > 0)
cout << "Your Body Mass Index is " << a << endl;
else
cout << "Invalid input." << endl;

if (0 < a < 20, w > 0, h > 0)
cout << "You have a low BMI." << endl;
else if (20 < a < 25, w > 0, h > 0)
cout << "You are within the healthy BMI range. Congratulations!" << endl;
else
cout << "You have exceeded the healthy BMI range." << endl;
return 0;
}


But the thing is, whenever I put in invalid numbers (-9001 or something), "You have a low BMI." STILL shows. What's the problem?

Will check this when I wake up in the morning, thanks in advance for any help! (going off to sleep;; )
POGGERS
50bani
Profile Blog Joined June 2009
Romania480 Posts
July 09 2009 16:15 GMT
#72
#include <iostream>
using namespace std;

void main()
{
double w, h;
double a;
cout << "Please enter your weight (in KG) and height (in meters)." << endl;
cin >> w >> h;
a = (w/(h*h));
if (w > 0, h > 0)
{cout << "Your Body Mass Index is " << a << endl;
if (0 < a < 20, w > 0, h > 0)
cout << "You have a low BMI." << endl;
else if (20 < a < 25, w > 0, h > 0)
cout << "You are within the healthy BMI range. Congratulations!" << endl;
else cout << "You have exceeded the healthy BMI range." << endl;
}
else
cout << "Invalid input." << endl;
}
I'm posting on twoplustwo because I have always been amazed at the level of talent that populates this site --- it's almost unparalleled on the Internet.
gokai
Profile Blog Joined August 2004
United States812 Posts
July 09 2009 16:17 GMT
#73
my god, i was good at math in highschool, so i thought i would be good at programming

boy was i wrong
Kau *
Profile Joined March 2007
Canada3500 Posts
July 09 2009 16:36 GMT
#74
Don't you need to use && or || for if statements?
Moderator
Cambium
Profile Blog Joined June 2004
United States16368 Posts
July 09 2009 16:43 GMT
#75
On July 10 2009 00:59 konadora wrote:
Bump

I've been doing something called the BMI test, here's my program:

Show nested quote +
#include <iostream>
using namespace std;

int main()
{
double w, h;
double a;
cout << "Please enter your weight (in KG) and height (in meters)." << endl;
cin >> w >> h;
a = (w/(h*h));
if (w > 0, h > 0)
cout << "Your Body Mass Index is " << a << endl;
else
cout << "Invalid input." << endl;

if (0 < a < 20, w > 0, h > 0)
cout << "You have a low BMI." << endl;
else if (20 < a < 25, w > 0, h > 0)
cout << "You are within the healthy BMI range. Congratulations!" << endl;
else
cout << "You have exceeded the healthy BMI range." << endl;
return 0;
}


But the thing is, whenever I put in invalid numbers (-9001 or something), "You have a low BMI." STILL shows. What's the problem?

Will check this when I wake up in the morning, thanks in advance for any help! (going off to sleep;; )


This doesn't give you compilation errors?!

if (0 < a < 20, w > 0, h > 0)

You probably meant || or && right...?
When you want something, all the universe conspires in helping you to achieve it.
Cambium
Profile Blog Joined June 2004
United States16368 Posts
July 09 2009 16:43 GMT
#76
On July 10 2009 01:36 Kau wrote:
Don't you need to use && or || for if statements?

yes, yes you do
When you want something, all the universe conspires in helping you to achieve it.
Cambium
Profile Blog Joined June 2004
United States16368 Posts
Last Edited: 2009-07-09 16:49:11
July 09 2009 16:47 GMT
#77
You need to figure out the inequalities... you have 0 < a < 20 and 20 < a < 25, i.e. you don't cover the case where a == 20.


#include <iostream>
using namespace std;

int main()
{
double w, h;
double a;
cout << "Please enter your weight (in KG) and height (in meters)." << endl;
cin >> w >> h;
// assuming you can't weight 0 kg and have 0 cm height ( h = 0 actually give you division by zero exception
if( w <= 0 || h <= 0 ) {
cout << "Invalid input." << endl;
return 0;
} else {
a = (w/(h*h));
cout << "Your Body Mass Index is " << a << endl;
}

if ( a > 0 && a < 20 )
cout << "You have a low BMI." << endl;
else if ( a > 20 && a < 25 )
cout << "You are within the healthy BMI range. Congratulations!" << endl;
else
cout << "You have exceeded the healthy BMI range." << endl;

return 0;
}
When you want something, all the universe conspires in helping you to achieve it.
pinenamu
Profile Blog Joined September 2006
United States770 Posts
July 09 2009 16:55 GMT
#78
On July 10 2009 01:17 gokai wrote:
my god, i was good at math in highschool, so i thought i would be good at programming

boy was i wrong

lol same here, i crawled out of my c programming and mips r2000 class.. phew, never have to program again (hopefully)

good luck kona! i hate programming with a passion so looking at this stuff makes me gag lol.
konadora *
Profile Blog Joined February 2009
Singapore66156 Posts
July 09 2009 22:37 GMT
#79
What does || do??
POGGERS
Cambium
Profile Blog Joined June 2004
United States16368 Posts
July 09 2009 22:40 GMT
#80
On July 10 2009 07:37 konadora wrote:
What does || do??


or...
When you want something, all the universe conspires in helping you to achieve it.
Prev 1 2 3 4 5 6 7 Next All
Please log in or register to reply.
Live Events Refresh
Wardi Open
11:00
#42
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Harstem 338
Rex 152
StarCraft: Brood War
Calm 13850
Sea 3530
Flash 1808
Bisu 670
Hyuk 471
Soma 421
ToSsGirL 415
EffOrt 414
Stork 388
Mini 306
[ Show more ]
BeSt 250
Light 210
ZerO 193
Snow 185
Soulkey 183
Zeus 145
TY 138
Pusan 110
hero 89
Sharp 88
Hyun 80
Sea.KH 66
Rush 61
Mind 56
Backho 51
sas.Sziky 37
Movie 18
Shinee 17
Free 16
Shine 16
Yoon 15
Noble 14
Barracks 14
sSak 14
ajuk12(nOOB) 10
scan(afreeca) 9
Bale 2
Britney 0
Stormgate
Nina80
Dota 2
qojqva2144
Gorgc1869
420jenkins877
XaKoH 575
BananaSlamJamma415
XcaliburYe398
League of Legends
singsing2649
Counter-Strike
x6flipin632
Super Smash Bros
Mew2King130
Westballz24
Other Games
B2W.Neo623
crisheroes373
hiko361
DeMusliM336
Pyrionflax275
Fuzer 260
Lowko225
QueenE26
ZerO(Twitch)9
Organizations
StarCraft 2
WardiTV869
Other Games
gamesdonequick701
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV496
League of Legends
• Stunt703
Upcoming Events
PiGosaur Monday
11h 26m
The PondCast
21h 26m
Replay Cast
1d 11h
RSL Revival
1d 21h
ByuN vs Classic
Clem vs Cham
WardiTV European League
2 days
Replay Cast
2 days
RSL Revival
2 days
herO vs SHIN
Reynor vs Cure
WardiTV European League
3 days
FEL
3 days
Korean StarCraft League
3 days
[ Show More ]
CranKy Ducklings
3 days
RSL Revival
3 days
FEL
4 days
Sparkling Tuna Cup
4 days
RSL Revival
4 days
FEL
5 days
BSL: ProLeague
5 days
Dewalt vs Bonyth
Replay Cast
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2025-06-28
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025
YaLLa Compass Qatar 2025

Upcoming

CSLPRO Last Chance 2025
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.