• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:39
CEST 08:39
KST 15:39
  • 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?6FEL Cracov 2025 (July 27) - $8000 live event13Esports 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
StarCraft Mass Recall: SC1 campaigns on SC2 thread The SCII GOAT: A statistical Evaluation Weekly Cups (June 23-29): Reynor in world title form? How does the number of casters affect your enjoyment of esports? Esports World Cup 2025 - Final Player Roster
Tourneys
HomeStory Cup 27 (June 27-29) WardiTV Mondays SOOPer7s Showmatches 2025 FEL Cracov 2025 (July 27) - $8000 live event $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/ BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest ASL20 Preliminary Maps Unit and Spell Similarities
Tourneys
[BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET The Casual Games of the Week Thread [Megathread] Daily Proleagues [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
Effective Commercial Building Cost Assessment Tips Trading/Investing Thread US Politics Mega-thread Stop Killing Games - European Citizens Initiative Things Aren’t Peaceful in Palestine
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: 572 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 States3696 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
Singapore66156 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
Singapore66156 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
Singapore66156 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
Singapore66156 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 4h 22m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft410
mcanning 147
StarCraft: Brood War
Larva 653
TY 485
Noble 12
Hm[arnc] 4
Bale 3
Britney 0
Dota 2
febbydoto37
League of Legends
JimRising 641
Counter-Strike
summit1g7775
Stewie2K832
Other Games
shahzam1030
KnowMe144
NeuroSwarm55
Mew2King41
Organizations
Other Games
gamesdonequick832
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush1589
• Stunt544
Upcoming Events
Wardi Open
4h 22m
PiGosaur Monday
17h 22m
The PondCast
1d 3h
Replay Cast
1d 17h
RSL Revival
2 days
ByuN vs Classic
Clem vs Cham
WardiTV European League
2 days
Replay Cast
2 days
RSL Revival
3 days
herO vs SHIN
Reynor vs Cure
WardiTV European League
3 days
FEL
3 days
[ Show More ]
Korean StarCraft League
3 days
CranKy Ducklings
4 days
RSL Revival
4 days
FEL
4 days
Sparkling Tuna Cup
5 days
RSL Revival
5 days
FEL
5 days
BSL: ProLeague
5 days
Dewalt vs Bonyth
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.