• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 09:07
CET 15:07
KST 23:07
  • 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
RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation12Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
Mech is the composition that needs teleportation t RotterdaM "Serral is the GOAT, and it's not close" RSL Season 3 - RO16 Groups C & D Preview [TLMC] Fall/Winter 2025 Ladder Map Rotation TL.net Map Contest #21: Winners
Tourneys
RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle BW General Discussion What happened to TvZ on Retro? Brood War web app to calculate unit interactions [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET
Strategy
PvZ map balance Current Meta Simple Questions, Simple Answers How to stay on top of macro?
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Clair Obscur - Expedition 33 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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread Russo-Ukrainian War Thread Artificial Intelligence Thread Canadian Politics Mega-thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2347 users

The Big Programming Thread - Page 111

Forum Index > General Forum
Post a Reply
Prev 1 109 110 111 112 113 1032 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.
ranshaked
Profile Blog Joined August 2010
United States870 Posts
January 26 2012 05:05 GMT
#2201
On January 26 2012 13:29 Kentor wrote:
that's where you end your braces? my head hurts...

and you need to initialize your loop counter variable.
plus you are never changing the variable sum. look at your program. at what point do you assign the variable sum anything new? certainly not this line

total=sum+number;


+ Show Spoiler +

#include <stdlib.h>
#include <stdio.h>

int main() {

int total;
int sum=0;
int number;
int i=1;
int other;
//I'm confused big time...I enter a #, number...
//Then i do an IF state ment to say if that number*number is greater than 500
//Then you should add the sum (initalized at zero) to the original number, which is number
//After 41 attempts, it takes the numbers in the sum and multiplies itself.
//How far am I off?
//Right now, it just continuously will ask for numbers over and over, but if i enter a number
//over 41, it will say "your answer is 0"

for(i; i!=6; i++){

printf("What is your number\n");
scanf("%d", &number);

other=number*number;

if(other>500){
total=sum+number;

total=total*total;}}


printf("The total is %d.\n",total);

system("pause");
return 0;
}


This is what I've got all together now. The problem is this:

I feel like I'm reading this thing wrong. I set it to run 5 tests. It works, but it only stores the LAST value that is more than 500.

For instance, I can type in, 5, 30, 20, 30, 25 and it will output 625...It only stores the last value that is over the 500 when multiplied. Shouldn't it be storing and adding them?
Should it go 30*30=900, so it stores 30 in the sum, then it sees 30 again, so it adds another 30 to the sum to equal 60, and then it sees 25 so it adds 25 to the sum, which will equal 85 and then multiples 85*85 to get 7225?

Does my sum have to be changed to sum=total or something? God I wish someone would just give me the answer so I can work it backward and see what's going on :/ I feel like an idiot when stuff doesn't click.
Kentor *
Profile Blog Joined December 2007
United States5784 Posts
January 26 2012 05:24 GMT
#2202
here's my answer

+ Show Spoiler +

#include <stdio.h>

int main(void)
{
int sum = 0;
int times = 5;

while (times--) {
int num;
printf("Enter number: ");
scanf("%d", &num);

if (num*num > 500) {
sum += num;
}
}

printf("Answer: %d\n", sum*sum);
return 0;
}

ranshaked
Profile Blog Joined August 2010
United States870 Posts
January 26 2012 05:38 GMT
#2203
Thank you, I finally figured it out :/ I wish we could have used a while loop :/ He specifically wanted us to us FOR, which really annoys me. Anyway, I got it working.

I used sum+=number to store it ;X

thank you a lot
Terranist
Profile Blog Joined March 2009
United States2496 Posts
January 26 2012 06:19 GMT
#2204
just beginning here. trying an exercise from my text. the exercise is to "make a carpool savings calculator" in C. any help on what i'm doing wrong would be much appreciated because i cannot figure it out.

running the program
+ Show Spoiler +

How many miles do you drive per day?
30
30
What is the cost of one gallon of gas?
3.80
How many miles per gallon do you get?
24
What is the parking fee per day at your destination?
4
What is the cost of tolls per day?
2
The total miles driven per day: 30.000000
The cost per gallon of gasoline: $30.000000
The average miles per gallon: 3.800000
The parking fees per day: $0.000000
The tolls per day: $0.000000
Your daily cost of driving to work is $0.000000
Press any key to continue . . .


why does it not accept the first input when asking how many miles i drive per day and why are the calculations messed up?

the code
+ Show Spoiler +

#include <stdio.h>
#include <stdlib.h>

void main()
{
float MPD, MPG, parking, tolls, total, CPG;

//user input

printf("How many miles do you drive per day?\n");
scanf("%f\n", &MPD);
printf("What is the cost of one gallon of gas?\n");
scanf("%f\n", &CPG);
printf("How many miles per gallon do you get?\n");
scanf("%f\n", &MPG);
printf("What is the parking fee per day at your destination?\n");
scanf("%f\n", &parking);
printf("What is the cost of tolls per day?\n");
scanf("%f\n", &tolls);

//calculations

total = tolls + parking + (MPD/MPG) * CPG;

//output to user

printf("The total miles driven per day: %f\n",MPD);
printf("The cost per gallon of gasoline: $%f\n", CPG);
printf("The average miles per gallon: %f\n", MPG);
printf("The parking fees per day: $%f\n", &parking);
printf("The tolls per day: $%f\n", &tolls);
printf("Your daily cost of driving to work is $%f\n", &total);


}
The Show of a Lifetime
Kentor *
Profile Blog Joined December 2007
United States5784 Posts
January 26 2012 06:36 GMT
#2205
try taking out "\n" in scanf
ObliviousNA
Profile Joined March 2011
United States535 Posts
Last Edited: 2012-01-26 07:07:18
January 26 2012 06:44 GMT
#2206
Taking the \n out of scanf will eliminate your 'double entry' for the first scanf, but your real error here is that you are using & (ampersands) on the printf statements at the end. The ampersand refers to a pointer (you're passing in the memory location essentially), so printing the memory results in garbage. In all likelihood, it was just keeping/printing what was in the buffer already.

That should fix it.
Theory is when you know everything but nothing works. Practice is when everything works but no one knows why. In our lab, theory and practice are combined: nothing works and no one knows why.
Terranist
Profile Blog Joined March 2009
United States2496 Posts
January 26 2012 20:57 GMT
#2207
thanks for the help guys. your advice really helped. i'm getting better at this one step at a time.
The Show of a Lifetime
Millitron
Profile Blog Joined August 2010
United States2611 Posts
January 26 2012 22:28 GMT
#2208
I don't have any question right now or anything, I just wanted to talk about how awesome sockets are.

I just started programming for my Networking class, and wow, sockets are pretty boss.

Who else loves sockets?
Who called in the fleet?
scarymeerkat
Profile Joined March 2011
Canada107 Posts
Last Edited: 2012-01-27 16:44:29
January 27 2012 15:51 GMT
#2209
another question here:

+ Show Spoiler +

int main ( void ){
FILE *file = fopen("num1.txt", "r");
char tmp[2], *nl;
int a[100], i;
for(i = 0; i < 100; i++){
fgets(tmp, 3, file);
nl = strrchr(tmp, '\n');
if (nl) *nl = '\0';
printf("%s ", tmp);
a[i] = atoi(tmp);
}

return 0;
}


I have that code, and what it is supposed to do is read in 100 int's from a text file. I read them into a temporary string, then convert that string to an integer and put the integer into an array. However, I'm encountering problems that have nothing to do with the integer array. When I run this code with a file that has a few 1 digit int's and mostly 2 digits ints, only around the first 50 are printed out by this: printf("%s ", tmp);
There is also a little bit of funky spacing when this occurs. However, if I run it with a different file, consisting entirely of 1 digit integers, all are printed out successfully.

I used an online random number generator to generate the numbers in the first file, and the output it gave had some funky spacing. However, I went through and got rid of all the tabs etc. that I could see so that hopefully each line was in the form:

11\n

The other thing is, I didn't expect that to make a difference, because tmp is only 2 char's big! And I called fgets with 3 as the second argument.

Is there something wrong with my code? Or is there some kind of unseen character in the text file I am using that is somehow screwing something up.

This is the problematic text file: num.txt - 291 bytes

EDIT: After a bit more searching, I found my problem. The problem was not with the file, but just the fact that it was reading in 2 digit numbers. I feel a bit silly now, because fgets was only reading in "11" of "11\n" leaving the \n untouched. Then the next time fgets was called, it would grab the newline, and do the same thing with that, resulting in appx. half my input being deprecated.
"From... BootySmackarack" - Artosis reading GOM interview questions
robih
Profile Joined September 2010
Austria1086 Posts
January 27 2012 19:38 GMT
#2210
hey guys

I'd like to contribute to some SC2 opensource project, but my google search didn't really give good results.

do you know about any where i could help?
ObliviousNA
Profile Joined March 2011
United States535 Posts
Last Edited: 2012-01-27 20:27:50
January 27 2012 20:19 GMT
#2211
On January 28 2012 00:51 scarymeerkat wrote:
another question here:

+ Show Spoiler +

int main ( void ){
FILE *file = fopen("num1.txt", "r");
char tmp[2], *nl;
int a[100], i;
for(i = 0; i < 100; i++){
fgets(tmp, 3, file);
nl = strrchr(tmp, '\n');
if (nl) *nl = '\0';
printf("%s ", tmp);
a[i] = atoi(tmp);
}

return 0;
}


I have that code, and what it is supposed to do is read in 100 int's from a text file. I read them into a temporary string, then convert that string to an integer and put the integer into an array. However, I'm encountering problems that have nothing to do with the integer array. When I run this code with a file that has a few 1 digit int's and mostly 2 digits ints, only around the first 50 are printed out by this: printf("%s ", tmp);
There is also a little bit of funky spacing when this occurs. However, if I run it with a different file, consisting entirely of 1 digit integers, all are printed out successfully.

I used an online random number generator to generate the numbers in the first file, and the output it gave had some funky spacing. However, I went through and got rid of all the tabs etc. that I could see so that hopefully each line was in the form:

11\n

The other thing is, I didn't expect that to make a difference, because tmp is only 2 char's big! And I called fgets with 3 as the second argument.

Is there something wrong with my code? Or is there some kind of unseen character in the text file I am using that is somehow screwing something up.

This is the problematic text file: num.txt - 291 bytes

EDIT: After a bit more searching, I found my problem. The problem was not with the file, but just the fact that it was reading in 2 digit numbers. I feel a bit silly now, because fgets was only reading in "11" of "11\n" leaving the \n untouched. Then the next time fgets was called, it would grab the newline, and do the same thing with that, resulting in appx. half my input being deprecated.


You probably figured this out, but you'll want to use one of the 'getline' functions to consume text until \n or EOF is reached. Also (and I'm no expert in c syntax) you'll want to phrase it something like this:

int index = 0;
while(getline(stream, stringVariable) != null)
{
if(index > arrayLength - 1)
{
break; //printout - shouldn't happen if your array/file are same size
}

stringArray[index++] = stringVariable;
//or
intArray[index++] = Convert.ToInteger(stringVariable);


}

fClose(stream);


This is generally considered safer/better, because it won't crash if you try to read past the end of the file. Also, you can change the amount of data you read in the file with only 1 variable.
Theory is when you know everything but nothing works. Practice is when everything works but no one knows why. In our lab, theory and practice are combined: nothing works and no one knows why.
mmp
Profile Blog Joined April 2009
United States2130 Posts
January 27 2012 20:57 GMT
#2212
On January 28 2012 04:38 robih wrote:
hey guys

I'd like to contribute to some SC2 opensource project, but my google search didn't really give good results.

do you know about any where i could help?

What did you have in mind? You'll probably have to start it yourself.
I (λ (foo) (and (<3 foo) ( T_T foo) (RAGE foo) )) Starcraft
Bigpet
Profile Joined July 2010
Germany533 Posts
January 28 2012 21:15 GMT
#2213
On January 28 2012 05:57 mmp wrote:
Show nested quote +
On January 28 2012 04:38 robih wrote:
hey guys

I'd like to contribute to some SC2 opensource project, but my google search didn't really give good results.

do you know about any where i could help?

What did you have in mind? You'll probably have to start it yourself.

well the TL App is tangentially SC2 related : http://www.teamliquid.net/forum/viewmessage.php?topic_id=304078

also there are several SC2 replay format parser like: https://github.com/GraylinKim/sc2reader/wiki
I'm NOT the caster with a similar nick
Jaso
Profile Blog Joined April 2010
United States2147 Posts
January 28 2012 23:27 GMT
#2214
With little to no knowledge in programming and an AP Computer Science book, about how long do you guys think it would take to learn Java to a high enough level to get a 5 on the AP test? (in hours, probably.)
derp
mmp
Profile Blog Joined April 2009
United States2130 Posts
January 28 2012 23:37 GMT
#2215
On January 29 2012 08:27 Jaso wrote:
With little to no knowledge in programming and an AP Computer Science book, about how long do you guys think it would take to learn Java to a high enough level to get a 5 on the AP test? (in hours, probably.)

Never took the AP comp sci, but at a glance it doesn't appear very relevant beyond basic OOP principles.

Read this to get started: http://docs.oracle.com/javase/tutorial/java/index.html
I (λ (foo) (and (<3 foo) ( T_T foo) (RAGE foo) )) Starcraft
Patriot.dlk
Profile Blog Joined October 2004
Sweden5462 Posts
January 28 2012 23:42 GMT
#2216
Recently tried some groovy. Mind blown!

Seriously awesome. Anyone else had the same experience?
mmp
Profile Blog Joined April 2009
United States2130 Posts
January 28 2012 23:54 GMT
#2217
On January 29 2012 08:42 Patriot.dlk wrote:
Recently tried some groovy. Mind blown!

Seriously awesome. Anyone else had the same experience?

Yeah, a friend and I used it for an nlp project. By the time we were done we barely understand what we had written inside all of the closures. What a bitch to debug.
I (λ (foo) (and (<3 foo) ( T_T foo) (RAGE foo) )) Starcraft
mmp
Profile Blog Joined April 2009
United States2130 Posts
January 28 2012 23:54 GMT
#2218
On January 29 2012 08:54 mmp wrote:
Show nested quote +
On January 29 2012 08:42 Patriot.dlk wrote:
Recently tried some groovy. Mind blown!

Seriously awesome. Anyone else had the same experience?

Yeah, a friend and I used it for an nlp project. By the time we were done we barely understand what we had written inside all of the closures. What a bitch to debug.

But it was groovy!
I (λ (foo) (and (<3 foo) ( T_T foo) (RAGE foo) )) Starcraft
Rainling
Profile Joined June 2011
United States456 Posts
Last Edited: 2012-02-18 01:46:12
January 29 2012 03:56 GMT
#2219
Edit: Fixed
Crazyeyes
Profile Blog Joined March 2008
Canada1342 Posts
Last Edited: 2012-01-29 08:03:54
January 29 2012 08:02 GMT
#2220
Alright, I've got a little question for you guys. I'm currently in third year university, major in computer science. Before University, I honestly didn't even know what programming was.

So anyways. As I've mentioned, I'm third year. All of my knowledge in computer programming comes from my classes. I'll admit I'm not the best student, but I do pay attention when I can and I'm not exactly failing my way through this. I don't ever program on my free time or read programming-related things that aren't school related.

So far, we've pretty much only learned Java when it comes to useful programmming languages. I did a bit in Scheme, a very small amount in Assembly (I forgot most of it, honestly. It was horrible), some HTML... and I'm currently learning C. Much harder than I expected. Pointers sorta confuse me sometimes.

The thing is, I feel like I don't know anything. I feel like pepole who have way less education than me are more capable than I am. I've never said "I've made a script to do...."
I dont even know what that is.

What I hope is going on is that I'm being given the basic (and hopefully more advanced, too) programming skills and knowledge that can be applied to all computer science, and then the more specific things I'll be able to pick up without too much effort. I'm hoping that when I sit down and am told to do X at some random job, I'll be able to do it and be surprised with how much I know.
I'm just not very sure.

So, to any of you who come from a similar background (learned everything at school), can you shed some light on your situation? Is this normal?
WeeEEeeEEEeeEEEeeeEEee!!
Prev 1 109 110 111 112 113 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 2h 53m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Reynor 714
TKL 416
IndyStarCraft 171
SteadfastSC 133
Rex 92
Railgan 56
StarCraft: Brood War
Britney 35658
Rain 4304
Horang2 1429
Jaedong 1193
Mini 978
Shuttle 552
EffOrt 498
Stork 443
firebathero 323
Last 273
[ Show more ]
BeSt 264
Leta 178
PianO 121
Shinee 77
Barracks 72
Hyun 71
Shine 66
ggaemo 65
LaStScan 49
JYJ45
Mong 42
Movie 30
sas.Sziky 26
ToSsGirL 25
Bale 24
soO 23
zelot 16
sorry 15
HiyA 13
Rock 7
Sacsri 5
Dota 2
Gorgc6417
qojqva1456
Dendi1117
XcaliburYe179
febbydoto14
Counter-Strike
oskar120
Other Games
FrodaN5128
B2W.Neo1757
DeMusliM360
Lowko255
KnowMe212
Fuzer 205
Pyrionflax196
Hui .174
Mew2King72
MindelVK15
Organizations
Dota 2
PGL Dota 2 - Main Stream11207
PGL Dota 2 - Secondary Stream2361
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Berry_CruncH150
• StrangeGG 38
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2003
• Ler46
League of Legends
• Nemesis1755
• Stunt938
Upcoming Events
IPSL
2h 53m
ZZZero vs rasowy
Napoleon vs KameZerg
OSC
4h 53m
BSL 21
5h 53m
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
19h 53m
RSL Revival
19h 53m
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
21h 53m
Cure vs TBD
Reynor vs TBD
WardiTV Korean Royale
21h 53m
BSL 21
1d 5h
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
1d 5h
Dewalt vs WolFix
eOnzErG vs Bonyth
Replay Cast
1d 8h
[ Show More ]
Wardi Open
1d 21h
Monday Night Weeklies
2 days
WardiTV Korean Royale
2 days
BSL: GosuLeague
3 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
BSL: GosuLeague
5 days
RSL Revival
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
WardiTV Korean Royale
6 days
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 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.