• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 18:01
CEST 00:01
KST 07:01
  • 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
Maestros of the Game: Week 1/Play-in Preview9[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9
Community News
Weekly Cups (August 25-31): Clem's Last Straw?32Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris46Weekly Cups (Aug 11-17): MaxPax triples again!15Weekly Cups (Aug 4-10): MaxPax wins a triple6
StarCraft 2
General
Speculation of future Wardii series Weekly Cups (August 25-31): Clem's Last Straw? Heaven's Balance Suggestions (roast me) Geoff 'iNcontroL' Robinson has passed away #1: Maru - Greatest Players of All Time
Tourneys
LiuLi Cup - September 2025 Tournaments Sea Duckling Open (Global, Bronze-Diamond) Sparkling Tuna Cup - Weekly Open Tournament Maestros of The Game—$20k event w/ live finals in Paris Monday Nights Weeklies
Strategy
Custom Maps
External Content
Mutation # 489 Bannable Offense Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies
Brood War
General
ASL20 General Discussion Starcraft at lower levels TvP BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion Victoria gamers
Tourneys
[Megathread] Daily Proleagues Is there English video for group selection for ASL [ASL20] Ro24 Group F [IPSL] CSLAN Review and CSLPRO Reimagined!
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread General RTS Discussion Thread Warcraft III: The Frozen Throne Nintendo Switch Thread Mechabellum
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 Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread YouTube Thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s) Gtx660 graphics card replacement
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
How Culture and Conflict Imp…
TrAiDoS
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
INDEPENDIENTE LA CTM
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 742 users

C++ revision help! - Page 3

Blogs > konadora
Post a Reply
Prev 1 2 3 4 5 6 7 Next All
tec27
Profile Blog Joined June 2004
United States3701 Posts
June 28 2009 16:24 GMT
#41
Yeah, thats just the variable you'd be inputting their answer to.
Can you jam with the console cowboys in cyberspace?
konadora *
Profile Blog Joined February 2009
Singapore66201 Posts
June 28 2009 16:29 GMT
#42
I don't quite get how to use it, I got this -
#include <iostream>
using namespace std;

int main()
{
double c,f;
cout << "Please choose whether you are entering the temperature in Centigrade (c) or Farenheit (f)." << endl;
if(myChar == 'c'){
f = ((c*1.8)+32);
cout << "The temperature is " << f << " degrees Farenheit." << endl;
}
else if(myChar == 'f'){
c = ((f-32)*5/9);
cout << "The temperature is " << c << " degrees Centigrade." << endl;
}
return 0;
}


With these errors:

1>c:\users\user\documents\visual studio 2008\projects\p1\p1\p1.cpp(8) : error C2065: 'myChar' : undeclared identifier
1>c:\users\user\documents\visual studio 2008\projects\p1\p1\p1.cpp(12) : error C2065: 'myChar' : undeclared identifier
POGGERS
fusionsdf
Profile Blog Joined June 2006
Canada15390 Posts
June 28 2009 16:35 GMT
#43
On June 29 2009 00:49 Uligor wrote:
Show nested quote +
On June 29 2009 00:48 konadora wrote:
My next question:

What data type do I use if I want to use a fraction? I'm currently doing this exercise where I'm supposed to convert inputted Farenheit temperature into centigrade and vice versa, and I need to use the fraction 5/9.


float or double.


yes

at least one of the two numbers must be a float or double, or you must explicitly cast one to a double <static_cast> or integer division will be performed instead.

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."
Superbia
Profile Blog Joined April 2008
Netherlands8889 Posts
June 28 2009 16:38 GMT
#44
On June 29 2009 01:29 konadora wrote:
I don't quite get how to use it, I got this -
Show nested quote +
#include <iostream>
using namespace std;

int main()
{
double c,f;
cout << "Please choose whether you are entering the temperature in Centigrade (c) or Farenheit (f)." << endl;
if(myChar == 'c'){
f = ((c*1.8)+32);
cout << "The temperature is " << f << " degrees Farenheit." << endl;
}
else if(myChar == 'f'){
c = ((f-32)*5/9);
cout << "The temperature is " << c << " degrees Centigrade." << endl;
}
return 0;
}


With these errors:

Show nested quote +
1>c:\users\user\documents\visual studio 2008\projects\p1\p1\p1.cpp(8) : error C2065: 'myChar' : undeclared identifier
1>c:\users\user\documents\visual studio 2008\projects\p1\p1\p1.cpp(12) : error C2065: 'myChar' : undeclared identifier


The code in this case would be

#include <iostream>
using namespace std;

int main()
{
double value;
char myChar;

cout << "Please enter C (Centigrade) or F (Farenheit) followed by the appropriate value" << endl;
cin >> myChar >> value;

if(myChar == 'C')
cout << "The temperature is " << (value*1.8)+32 << " degrees Farenheit." << endl;
else if(myChar == 'F')
cout << "The temperature is " << (value-32)*5/9 << " degrees Centigrade." << endl;
else
cout << "Please insert a correct prefix" << endl;

return 0;
}


Please note how I replaced double f/c with double value and how I moved the calculations to inside the cout << instruction.
The example input for this piece of code would be "F 1.42". (note: this would be a rather unpleasant temperature)
Minimal effort.
konadora *
Profile Blog Joined February 2009
Singapore66201 Posts
Last Edited: 2009-06-28 16:42:50
June 28 2009 16:41 GMT
#45
The char is the same as 'int', except it is not just integers, but characters, that's all, right?

Also, the purpose of putting the calculations inside the cout << instruction would be to shorten the entire program, as well as to remove unnecessary variables, right?

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.
POGGERS
Superbia
Profile Blog Joined April 2008
Netherlands8889 Posts
June 28 2009 16:45 GMT
#46
On June 29 2009 01:41 konadora wrote:
The char is the same as 'int', except it is not just integers, but characters, that's all, right?


char is 8 bit, int is 32 bit (though for int it's compiler specific). I think this might go a bit too far for now, you should use char to save single-byte characters (e.g. 'e', '0', etc).

On June 29 2009 01:41 konadora wrote:Also, the purpose of putting the calculations inside the cout << instruction would be to shorten the entire program, as well as to remove unnecessary variables, right?


Yeah, it's basically to remove unnecessary variables.
Minimal effort.
GHOSTCLAW
Profile Blog Joined February 2008
United States17042 Posts
Last Edited: 2009-06-28 16:46:55
June 28 2009 16:46 GMT
#47
oops.
PhotographerLiquipedia. Drop me a pm if you've got questions/need help.
konadora *
Profile Blog Joined February 2009
Singapore66201 Posts
June 28 2009 16:50 GMT
#48
Thanks for all the help for this noob here, I don't think I can keep awake anymore, already drank 4 cups of coffee. Will wake up in 6 hours' time and continue from there, going to get some sleep (almost 1am here). Thanks all once again!
POGGERS
okayokes
Profile Joined March 2004
United States39 Posts
June 28 2009 16:50 GMT
#49
On June 29 2009 01:41 konadora wrote:
The char is the same as 'int', except it is not just integers, but characters, that's all, right?

Also, the purpose of putting the calculations inside the cout << instruction would be to shorten the entire program, as well as to remove unnecessary variables, right?

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.



char holds one ASCII character iirc. If you want a sentence you should use a string. Though you could also use a character array.

char myChar[] = {'H', 'e', 'l', 'l', 'o'};

string myString = "Hello";
-,-
Superbia
Profile Blog Joined April 2008
Netherlands8889 Posts
Last Edited: 2009-06-28 16:59:17
June 28 2009 16:55 GMT
#50
On June 29 2009 01:35 fusionsdf wrote:
Show nested quote +
On June 29 2009 00:49 Uligor wrote:
On June 29 2009 00:48 konadora wrote:
My next question:

What data type do I use if I want to use a fraction? I'm currently doing this exercise where I'm supposed to convert inputted Farenheit temperature into centigrade and vice versa, and I need to use the fraction 5/9.


float or double.


yes

at least one of the two numbers must be a float or double, or you must explicitly cast one to a double <static_cast> or integer division will be performed instead.



With the code "(value-32)*5/9" (value being double) the compiler (MSVS08) generated FPU instructions for 5/9, so in this case it was not necessary. However I see your concern because compilers like to precalculate things.
Minimal effort.
Divinek
Profile Blog Joined November 2006
Canada4045 Posts
June 28 2009 17:07 GMT
#51
are you in uni for a class or something? if you are im a bit confused how you dont understand any of this. If it's a highschool class or something then maybe i get it but some of this stuff you are asking is like first few weeks of learning. I'm just honestly curious not trying to be a dick
Never attribute to malice that which can be adequately explained by stupidity.
Oh goodness me, FOX tv where do you get your sight? Can't you keep track, the puck is black. That's why the ice is white.
konadora *
Profile Blog Joined February 2009
Singapore66201 Posts
June 28 2009 17:20 GMT
#52
I'm in high school, started 3 months ago, but I had gotten sick around March (which was the period where my sudden burst in activeness on TL occurred), missing school for a month, after which I failed to revise enough lol.

Not to mention the one month summer break (which ended today) made me just slack all the way.
POGGERS
Scorch
Profile Blog Joined March 2008
Austria3371 Posts
June 28 2009 17:35 GMT
#53
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.
unknown.sam
Profile Joined May 2007
Philippines2701 Posts
June 28 2009 17:53 GMT
#54
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.

this
"Thanks for the kind words, but if SS is the most interesting book you've ever read, you must have just started reading a couple of weeks ago." - Mark Rippetoe
AoN.DimSum
Profile Blog Joined September 2008
United States2983 Posts
June 28 2009 18:03 GMT
#55
http://cplusplus.com/ is a good site
by my idol krokkis : "U better hope Finland wont have WCG next year and that I wont gain shitloads of skill, cause then I will wash ur mouth with soap, little man."
okayokes
Profile Joined March 2004
United States39 Posts
Last Edited: 2009-06-28 18:23:06
June 28 2009 18:18 GMT
#56
cool site. C++ seems confusing at first but it gets alot easier over time. Certain things I'm trying to learn now are hard to get my head around. Like recursion <_>;

code like this can be hard to get a grip on (atleased for me):

void permute(string current, string rest)
{
if (rest == "")
{
cout << current << endl;
++counter;
}else{
for ( int i = 0; i < rest.length(); i++ )
{
string next = current + rest[i];
string remaining = rest.substr(0, i)
+ rest.substr(i+1);
permute(next, remaining);
}
}
}

the syntax itself is not the difficult aspect, but keeping track of every stack frame and how it unravels is difficult ~_~. There are some great stanford lectures posted up on youtube though! http://www.youtube.com/profile?user=stanforduniversity&view=playlists

Programming Methodology is the beginners course using mostly Java.
Programming Abstractions is the intermediate course using C++
Programming Paradigms is the advanced course which I haven't looked at.
-,-
DrLefTy
Profile Blog Joined June 2009
United States36 Posts
June 28 2009 18:53 GMT
#57
if you want to learn recursion, learn how to code in lisp or scheme.
fusionsdf
Profile Blog Joined June 2006
Canada15390 Posts
Last Edited: 2009-06-28 20:59:03
June 28 2009 20:53 GMT
#58
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.
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."
eci
Profile Joined July 2008
Germany45 Posts
June 28 2009 21:45 GMT
#59
back to the question void main() and int main() - int main() starts an application which returns an int number ( -2^31..(2^31-1) ) while void main() always returns 0. How this returned value depends on your operating system, on linux you can see that result code e.g. by "echo $?" on bash command line.
I think void main() is also not in the recent standard any more, so if you do not know for sure just use "int main()" and don't forget to return a value ( return 0; - you could also write return -1; if an error happend - but its kind of old school )

Btw: This question is rather unimportant - try to write more code - implement some algorithms ( e.g. bread death search in a graph ) - use stl standard library - use external librarys like boost

hf in coding
Vorwaerts!
liquorice
Profile Joined August 2008
United States170 Posts
June 28 2009 23:19 GMT
#60
On June 29 2009 05:53 fusionsdf wrote:
Show nested quote +
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.
fuck yeah zerglings!
Prev 1 2 3 4 5 6 7 Next All
Please log in or register to reply.
Live Events Refresh
Next event in 1h 59m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
JuggernautJason79
StarCraft: Brood War
Britney 19530
Dewaltoss 108
Aegong 41
sSak 40
NaDa 22
yabsab 7
Counter-Strike
Stewie2K737
Foxcn303
Super Smash Bros
Liquid`Ken21
Heroes of the Storm
Liquid`Hasu492
Other Games
summit1g3062
Grubby2345
FrodaN1368
C9.Mang0161
Trikslyr130
Livibee82
Mew2King69
Nathanias33
Chillindude23
ViBE22
rGuardiaN20
Kaelaris9
Organizations
Other Games
BasetradeTV12
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• davetesta74
• StrangeGG 31
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• Kozan
• IndyKCrew
StarCraft: Brood War
• Pr0nogo 4
• ZZZeroYoutube
• STPLYoutube
• BSLYoutube
Dota 2
• masondota22322
League of Legends
• Doublelift5328
• TFBlade360
• HappyZerGling72
Counter-Strike
• imaqtpie1111
• Shiphtur196
Other Games
• Scarra603
Upcoming Events
Replay Cast
1h 59m
The PondCast
11h 59m
RSL Revival
11h 59m
Maru vs SHIN
MaNa vs MaxPax
Maestros of the Game
18h 59m
Classic vs TriGGeR
Reynor vs SHIN
OSC
1d 4h
MaNa vs SHIN
SKillous vs ShoWTimE
Bunny vs TBD
Cham vs TBD
RSL Revival
1d 11h
Reynor vs Astrea
Classic vs sOs
Maestros of the Game
1d 18h
Serral vs Ryung
ByuN vs Zoun
BSL Team Wars
1d 20h
Team Bonyth vs Team Dewalt
CranKy Ducklings
2 days
RSL Revival
2 days
GuMiho vs Cham
ByuN vs TriGGeR
[ Show More ]
Cosmonarchy
2 days
TriGGeR vs YoungYakov
YoungYakov vs HonMonO
HonMonO vs TriGGeR
Maestros of the Game
2 days
Solar vs Bunny
Clem vs Rogue
[BSL 2025] Weekly
2 days
RSL Revival
3 days
Cure vs Bunny
Creator vs Zoun
Maestros of the Game
3 days
Maru vs Lambo
herO vs ShoWTimE
BSL Team Wars
3 days
Team Hawk vs Team Sziky
Sparkling Tuna Cup
4 days
Monday Night Weeklies
4 days
Liquipedia Results

Completed

CSL Season 18: Qualifier 2
SEL Season 2 Championship
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL 2025 AUTUMN (S18)
Maestros of the Game
Sisters' Call Cup
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

LASL Season 20
2025 Chongqing Offline CUP
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
EC S1
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
MESA Nomadic Masters Fall
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
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.