• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:26
CEST 15:26
KST 22:26
  • 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
[ASL19] Finals Recap: Standing Tall10HomeStory 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 Energy6
Community News
Firefly given lifetime ban by ESIC following match-fixing investigation5$25,000 Streamerzone StarCraft Pro Series announced4Weekly Cups (June 30 - July 6): Classic Doubles6[BSL20] Non-Korean Championship 4x BSL + 4x China9Flash Announces Hiatus From ASL66
StarCraft 2
General
TL Team Map Contest #4: Winners Weekly Cups (June 30 - July 6): Classic Doubles The SCII GOAT: A statistical Evaluation The GOAT ranking of GOAT rankings Firefly given lifetime ban by ESIC following match-fixing investigation
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event $25,000 Streamerzone StarCraft Pro Series announced Sparkling Tuna Cup - Weekly Open Tournament RSL: Revival, a new crowdfunded tournament series WardiTV Mondays
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ i aint gon lie to u bruh... ASL20 Preliminary Maps [G] Progamer Settings [ASL19] Finals Recap: Standing Tall
Tourneys
[BSL20] Non-Korean Championship 4x BSL + 4x China [BSL20] Grand Finals - Sunday 20:00 CET CSL Xiamen International Invitational The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread 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
Positive Thoughts on Setting Up a Dual-Caliber FX
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
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread Summer Games Done Quick 2025! Stop Killing Games - European Citizens Initiative
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread 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
momentary artworks from des…
tankgirl
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 590 users

The Big Programming Thread - Page 178

Forum Index > General Forum
Post a Reply
Prev 1 176 177 178 179 180 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
adwodon
Profile Blog Joined September 2010
United Kingdom592 Posts
Last Edited: 2012-10-17 21:31:58
October 17 2012 21:28 GMT
#3541
On October 18 2012 06:11 Kambing wrote:
Show nested quote +
On October 18 2012 00:36 Snuggles wrote:
For some reason my school decided to switch languages for my intro CS course, so instead of learning C++ we're starting out with Python. Then later on in the second semester of the intro course we get into C++ and Java. Any idea why they would do that? I would think that just jumping into C++ and Java would seem more beneficial. My father's friend is a software Architect of some sort and when I told him that I wanted to get into the technical side of things, I should devote time to learning Java @_@.

I really wish that I settled down and decided to go with CS as my minor right from the get go because writing up a program to solve stats or any homework that has to deal with math would've made life so much easier...


Python is far more friendly to new programmers than Java and C++. Among other things, you can emphasize good programming fundamentals in a simpler language like Python without having to also get bogged down in too many unnecessary details like with Java and C++.


Just to reiterate the same point.

You can learn to apply things easier with python, I'm doing a Berkeley AI course at the moment in Python. The language is beautifully simple and so you can focus on the concepts you are learning as opposed to the quirks of the language as you probably would with C/C++/Java if that's what you started out on.

One important thing to know is that a good programmer doesn't just know one language. Nor is the first language you learn likely to be the one you stick with. What you're feeling is the drive to 'jump the gun'. You've got plenty of years to learn / master Java. Best start with something easier to deal with first. Besides you can't really decide you want to do something seriously technical when you're just starting out, 2-3 years into your course you may decide that you really dislike working with Java and prefer Python for whatever reason, getting advice from people in industry is great, but you'll soon know that one problem with experienced programmers is they're often very opinionated. I've had people tell me C++ is the greatest thing since sliced bread and Java is utter garbage, that Java just makes life easier, that Python is the greatest thing since sliced bread, that people have never been as productive since C# was introduced etc etc
Take advice with a grain of salt, and form your own opinions, just try to be a bit more balanced than some people, almost all languages, especially the commonly used ones are fantastic and serve their purpose well.

Generally I think a good CS course should teach you lots of languages and the differences between them, rather than focusing on one, it allows you to assess what language suits the problem at hand but also will prepare you better for the future when languages will obviously change.
white_horse
Profile Joined July 2010
1019 Posts
Last Edited: 2012-10-17 21:43:47
October 17 2012 21:33 GMT
#3542
I finally got the program working. to everyone that helped me with my program, thanks^^ I wish I could buy you dinner or something. The program works but its slow (takes a minute to get all primes between 4 and 1 million) so I'm working on that. I have something else thats weird.

+ Show Spoiler +


if (a%2 == 0)
{
cout << "The number input was not prime number" << endl;
}
else if (a%2 != 0)
{
bool prime = true;
for (int i = 2; i <= sqrt(a); i++)
{
if (a%i == 0)
{
prime = false;
cout << "The number input was not prime number" << endl;
}
}

if (prime == true)
{
cout << "The number input was a prime number" << endl;
}
}



"a" is the inputted number and the code checks to see if the number is a prime or not. It works except that when you put in something like 81 for a, it outputs "The number input was not prime number" twice. Can you help me figure out why its doing that?
Translator
fabiano
Profile Blog Joined August 2009
Brazil4644 Posts
October 17 2012 21:43 GMT
#3543
Try adding a break after the "The number input was not prime number" to exit the loop asap.


(...)
cout << "The number input was not prime number" << endl;
break;
(...)


Not sure if it is really the problem though.
"When the geyser died, a probe came out" - SirJolt
white_horse
Profile Joined July 2010
1019 Posts
October 17 2012 21:45 GMT
#3544
On October 18 2012 06:43 fabiano wrote:
Try adding a break after the "The number input was not prime number" to exit the loop asap.


(...)
cout << "The number input was not prime number" << endl;
break;
(...)


Not sure if it is really the problem though.


I thought of that but our class has this dumb policy where breaks and continues are not allowed -_-
Translator
DeltaX
Profile Joined August 2011
United States287 Posts
October 17 2012 21:50 GMT
#3545
On October 18 2012 06:33 white_horse wrote:
I finally got the program working. to everyone that helped me with my program, I wish I could buy you dinner or something, thanks. The program works but its slow (takes a minute to get all primes between 4 and 1 million) so I'm working on that. I have something else thats weird.

+ Show Spoiler +


if (a%2 == 0)
{
cout << "The number input was not prime number" << endl;
}
else if (a%2 != 0)
{
bool prime = true;
for (int i = 2; i <= sqrt(a); i++)
{
if (a%i == 0)
{
prime = false;
cout << "The number input was not prime number" << endl;
}
}

if (prime == true)
{
cout << "The number input was a prime number" << endl;
}
}



"a" is the inputted number and the code checks to see if the number is a prime or not. It works except that when you put in something like 81 for a, it outputs "The number input was not prime number" twice. Can you help me figure out why its doing that?


It will output that multiple times because your loop keeps running after you know that the number is not prime. the condition for the if statement is true for i = 3 and i = 9. Once you know that the number is not prime, then you can stop the loop and keep going. The best way to do this depends on the context of the code and where it is in your program.
Kambing
Profile Joined May 2010
United States1176 Posts
October 17 2012 21:53 GMT
#3546
On October 18 2012 06:45 white_horse wrote:
Show nested quote +
On October 18 2012 06:43 fabiano wrote:
Try adding a break after the "The number input was not prime number" to exit the loop asap.


(...)
cout << "The number input was not prime number" << endl;
break;
(...)


Not sure if it is really the problem though.


I thought of that but our class has this dumb policy where breaks and continues are not allowed -_-


With good reason. Breaks and continues can disrupt local code reasoning. In particular, you should think about the exit condition for your loop and how it relates to when you get into the if-statement. How should it change to reflect the fact that you entered into that if-statement?
fabiano
Profile Blog Joined August 2009
Brazil4644 Posts
October 17 2012 21:53 GMT
#3547
Well then, time to be a little dirty:

(...)
cout << "The number input was not prime number" << endl;
i = a;
(...)

Certainly looks the wrong way to code, but should have the same effect :p
"When the geyser died, a probe came out" - SirJolt
DeltaX
Profile Joined August 2011
United States287 Posts
Last Edited: 2012-10-17 21:56:42
October 17 2012 21:55 GMT
#3548
On October 18 2012 06:45 white_horse wrote:
Show nested quote +
On October 18 2012 06:43 fabiano wrote:
Try adding a break after the "The number input was not prime number" to exit the loop asap.


(...)
cout << "The number input was not prime number" << endl;
break;
(...)


Not sure if it is really the problem though.


I thought of that but our class has this dumb policy where breaks and continues are not allowed -_-


You could also try


(...)
cout << "The number input was not prime number" << endl;
i = a;
(...)


This would end the loop right away.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2012-10-18 01:07:05
October 17 2012 21:58 GMT
#3549
Well uh, honestly the first if statement is unnecessary since you do the check again in the for loop.

And you should bring the cout statements outside the loop too, that way you can separate the printing to console from the prime verification.

Should also add in the two suggestions above me for more efficiency.**

There's a lot of warning signs going off in my head from that code though.


@below, his input guarantees a to be between 4 and 1,000,000, so it's okay.
There is no one like you in the universe.
tofucake
Profile Blog Joined October 2009
Hyrule19031 Posts
Last Edited: 2012-10-17 22:00:27
October 17 2012 21:59 GMT
#3550
uhhh...white_horse...

2 is prime

and fails the first check

also, by definition, anything mod 2 is either 0 or 1, so you don't need to elseif, just else
Liquipediaasante sana squash banana
Thadorus
Profile Joined June 2010
Canada136 Posts
October 17 2012 22:44 GMT
#3551
anyone know what would cause vim to freeze? Just started using it and i was editing a program and it suddenly wouldn't let me do anything in insert mode and after a while (5 mins) it crashed and said priWrite failed: Broken pipe;.

I wasn't doing anything important but kinda scares me that it crash like that and now im wondering if its normally that unreliable?
berated-
Profile Blog Joined February 2007
United States1134 Posts
October 18 2012 00:57 GMT
#3552
On October 18 2012 07:44 Thadorus wrote:
anyone know what would cause vim to freeze? Just started using it and i was editing a program and it suddenly wouldn't let me do anything in insert mode and after a while (5 mins) it crashed and said priWrite failed: Broken pipe;.

I wasn't doing anything important but kinda scares me that it crash like that and now im wondering if its normally that unreliable?


Sounds more like you were using vim with a ssh session, and the ssh session failed not the vim edit. You're not using vim locally, are you?
Kambing
Profile Joined May 2010
United States1176 Posts
October 18 2012 01:04 GMT
#3553
On October 18 2012 06:53 fabiano wrote:
Well then, time to be a little dirty:

(...)
cout << "The number input was not prime number" << endl;
i = a;
(...)

Certainly looks the wrong way to code, but should have the same effect :p


While that works, that's not optimal because the condition for breaking the loop is not explicit by inspection in the loop guard. You have a variable prime that is false only when you have proven that the number is not a prime. You should be using that instead.
Cambium
Profile Blog Joined June 2004
United States16368 Posts
October 18 2012 01:09 GMT
#3554
On October 18 2012 06:33 white_horse wrote:
I finally got the program working. to everyone that helped me with my program, thanks^^ I wish I could buy you dinner or something. The program works but its slow (takes a minute to get all primes between 4 and 1 million) so I'm working on that. I have something else thats weird.

+ Show Spoiler +


if (a%2 == 0)
{
cout << "The number input was not prime number" << endl;
}
else if (a%2 != 0)
{
bool prime = true;
for (int i = 2; i <= sqrt(a); i++)
{
if (a%i == 0)
{
prime = false;
cout << "The number input was not prime number" << endl;
}
}

if (prime == true)
{
cout << "The number input was a prime number" << endl;
}
}



"a" is the inputted number and the code checks to see if the number is a prime or not. It works except that when you put in something like 81 for a, it outputs "The number input was not prime number" twice. Can you help me figure out why its doing that?


here's one reason why it's slow:

let's loop through this starting at 3 (2 is a prime...), and let's say a is 1 million

i = 3
temp = sqrt(1M)
3 < temp?

i = 4
temp = sqrt(1M)
4 < temp?

i = 5
temp = sqrt(1M)
5 < temp?

i = 6
temp = sqrt(1M)
6 < temp?

i = 7
temp = sqrt(1M)
7 < temp?
...


Do you notice that there is a step that is completely unnecessary?
When you want something, all the universe conspires in helping you to achieve it.
tofucake
Profile Blog Joined October 2009
Hyrule19031 Posts
October 18 2012 01:52 GMT
#3555
On October 18 2012 06:45 white_horse wrote:
Show nested quote +
On October 18 2012 06:43 fabiano wrote:
Try adding a break after the "The number input was not prime number" to exit the loop asap.


(...)
cout << "The number input was not prime number" << endl;
break;
(...)


Not sure if it is really the problem though.


I thought of that but our class has this dumb policy where breaks and continues are not allowed -_-

set i = a then
Liquipediaasante sana squash banana
GreEny K
Profile Joined February 2008
Germany7312 Posts
October 18 2012 02:12 GMT
#3556
Ok guys, I'm a new CS major and even though I've been on TL for a while I never really looked in this thread. I was just pondering something my professor said the other day and it doesn't click in my head.

He said that using a while loop, you can pick a number and then add up all of the numbers up to that number on the run, so to speak. I don't understand how you can do that.

Can someone write out the code to explain this?
Why would you ever choose failure, when success is an option.
Craton
Profile Blog Joined December 2009
United States17247 Posts
Last Edited: 2012-10-18 02:48:55
October 18 2012 02:29 GMT
#3557
I don't know what you're asking, exactly? It sounds more like the logic you'd do in a for next than something you'd want in a while loop. Naturally you could accomplish the same thing with any loop type, but you generally use what makes the most sense for the problem (i.e. for next over while). I'm assuming you mean something else, though.

int count;
someVal = 10;

for (int i = 1; i <= someVal; i++)
{
count += i;
}

Console.WriteLine(count.ToString());

int count;
int someVal = 10;
int curVal = 1;

while (curVal <= someVal)
{
count += curVal;
curVal ++;
}

Console.WriteLine(count.ToString());
twitch.tv/cratonz
GreEny K
Profile Joined February 2008
Germany7312 Posts
October 18 2012 02:46 GMT
#3558
On October 18 2012 11:29 Craton wrote:
I don't know what you're asking, exactly? It sounds more like the logic you'd do in a for next than something you'd want in a while loop. Naturally you could accomplish the same thing with any loop type, but you generally use what makes the most sense for the problem (i.e. for next over while). I'm assuming you mean something else, though.

int count;
someVal = 10;

for (int i = 1; i <= someVal; i++)
{
count += i;
}

int count;
int someVal = 10;
int curVal = 1;

while (curVal <= someVal)
{
count += curVal;
curVal ++;
}


Sorry, I'll try to explain it better. User inputs a number (a positive number), let's say 5. Then the program adds all of the numbers up to what the user input (1+2+3+4+5) and then the total is displayed. He said we would be doing something like this in lab next week, and I don't want to show up unprepared but I don't really understand how you can make them add together. We haven't covered for loops yet, so he said we would be using do while loops for validation (in case a user inputs a negative number) and while loops for the actual process.
Why would you ever choose failure, when success is an option.
Craton
Profile Blog Joined December 2009
United States17247 Posts
Last Edited: 2012-10-18 02:56:03
October 18 2012 02:48 GMT
#3559
Well I already showed you how to add them in both examples.

The only thing about validation in a while loop that makes sense is if you have some kind of exit condition that involves entering a negative number (and if not it shows you the sum then loops back around asking for a new number). I'll exclude validating that you enter an integer, since you are still at the very basics.

This is C#. Other languages will vary slightly.


int inputNum;

Console.Write("Enter a number: ");
inputNum = Convert.ToInt32(Console.ReadLine());

while (inputNum > 0)
{
//put summation logic here

Console.Write("Enter a number: ");
inputNum = Convert.ToInt32(Console.ReadLine());
}

There are many other, and probably better, ways of doing this kind of validation (and with less redundancy).

twitch.tv/cratonz
GreEny K
Profile Joined February 2008
Germany7312 Posts
October 18 2012 02:53 GMT
#3560
On October 18 2012 11:48 Craton wrote:
Well I already showed you how to add them in both examples.

The only thing about validation in a while loop that makes sense is if you have some kind of exit condition that involves entering a negative number (and if not it shows you the sum then loops back around asking for a new number).


Ok, I figured you covered it pretty well but just wanted to make sure. Thanks man! I'll be visiting this thread more often to try and get good lol.

Thanks again
Why would you ever choose failure, when success is an option.
Prev 1 176 177 178 179 180 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 2h 34m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ForJumy 92
StarCraft: Brood War
Shuttle 2520
Flash 2081
Bisu 1604
firebathero 1417
EffOrt 903
actioN 535
Larva 515
Mini 504
Hyuk 382
Soulkey 313
[ Show more ]
Snow 308
Last 216
hero 186
Zeus 175
Soma 174
ToSsGirL 155
soO 124
TY 119
Hyun 103
Pusan 64
sorry 62
Rush 39
JYJ35
Noble 33
Sacsri 24
JulyZerg 24
GoRush 21
Yoon 19
HiyA 15
yabsab 15
Movie 14
IntoTheRainbow 10
zelot 8
Icarus 7
Terrorterran 3
ivOry 1
GuemChi 0
Dota 2
Gorgc10013
qojqva1724
XcaliburYe235
League of Legends
singsing2327
Counter-Strike
x6flipin367
allub217
byalli192
chrisJcsgo117
flusha22
Heroes of the Storm
Khaldor106
Other Games
tarik_tv23511
gofns13461
B2W.Neo1144
FrodaN635
shahzam570
DeMusliM512
hiko500
Fuzer 239
crisheroes179
QueenE37
Organizations
Other Games
gamesdonequick35820
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• HeavenSC 10
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 18
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis3723
Upcoming Events
uThermal 2v2 Circuit
2h 34m
WardiTV European League
2h 34m
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
Replay Cast
10h 34m
RSL Revival
20h 34m
ByuN vs SHIN
Clem vs Reynor
OSC
23h 34m
Replay Cast
1d 10h
RSL Revival
1d 20h
Classic vs Cure
FEL
2 days
OSC
2 days
RSL Revival
2 days
[ Show More ]
FEL
2 days
FEL
3 days
CSO Cup
3 days
BSL20 Non-Korean Champi…
3 days
Bonyth vs QiaoGege
Dewalt vs Fengzi
Hawk vs Zhanhun
Sziky vs Mihu
Mihu vs QiaoGege
Zhanhun vs Sziky
Fengzi vs Hawk
Sparkling Tuna Cup
3 days
RSL Revival
3 days
FEL
4 days
BSL20 Non-Korean Champi…
4 days
Bonyth vs Dewalt
QiaoGege vs Dewalt
Hawk vs Bonyth
Sziky vs Fengzi
Mihu vs Zhanhun
QiaoGege vs Zhanhun
Fengzi vs Mihu
Replay Cast
5 days
Liquipedia Results

Completed

Proleague 2025-07-07
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
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

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
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.