• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 03:22
CET 09:22
KST 17:22
  • 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 Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets0$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)12Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7[BSL21] Non-Korean Championship - Starts Jan 103SC2 All-Star Invitational: Jan 17-1822
StarCraft 2
General
Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns Spontaneous hotkey change zerg Chinese SC2 server to reopen; live all-star event in Hangzhou SC2 All-Star Invitational: Jan 17-18
Tourneys
$25,000 Streamerzone StarCraft Pro Series announced $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) WardiTV Winter Cup WardiTV Mondays SC2 AI Tournament 2026
Strategy
Simple Questions Simple Answers
Custom Maps
Map Editor closed ?
External Content
Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes
Brood War
General
Potential ASL qualifier breakthroughs? BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest Data analysis on 70 million replays
Tourneys
[Megathread] Daily Proleagues [BSL21] Grand Finals - Sunday 21:00 CET [BSL21] Non-Korean Championship - Starts Jan 10 SLON Grand Finals – Season 2
Strategy
Game Theory for Starcraft Simple Questions, Simple Answers Current Meta [G] How to get started on ladder as a new Z player
Other Games
General Games
Beyond All Reason Nintendo Switch Thread Awesome Games Done Quick 2026! Mechabellum Stormgate/Frost Giant Megathread
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
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine Trading/Investing Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced
Blogs
My 2025 Magic: The Gathering…
DARKING
Physical Exercise (HIIT) Bef…
TrAiDoS
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1262 users

The Big Programming Thread - Page 110

Forum Index > General Forum
Post a Reply
Prev 1 108 109 110 111 112 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
Last Edited: 2012-01-24 15:50:53
January 24 2012 15:48 GMT
#2181
Problem D: Repeating the Program Run
In this part, you must embed all of Part C in a FOR-Loop that runs N times.
At the start, prompt for an integer value of N, read it in and run the loop. So, if N is
typed in at the prompt as 2, your solution to Part C will first run once, prompting for
the two state names, etc., and will give its result; then, it will prompt a second time
and read in a set of two states and their votes and give a result.


Basically that's what I have to do....if I use: for(i=0; i < timestorun; i++) and have int=i; and int timestorun=2 it will run PERFECT, but if I prompt the user
printf("How many times do you want to run this program?\n");
scanf("%d", timestorun);

it won't work :/

edit:
Wow, nevermind...I forgot the &timestorun

DUH. I just needed to retype it to see what I was missing. I haven't learned how to "debug" yet. Any recommendations ?

edit2: Sorry, it's really hard to explain it sometimes. This is all brand new to me. Only my second week doing this.
Lorac
Profile Joined April 2010
Canada27 Posts
Last Edited: 2012-01-24 21:23:48
January 24 2012 18:03 GMT
#2182
Hello I'm new to programming and I have to figure out an algorithm, the Formula of Brouncker for 4/pi William Brouncker

Sorry for the french because the english one doesn't show the right formula

I know how to do it on paper but it seems getting it into Python is a bit different so I could use some help :D
The user of the program as to input a precision value in real between 0 and 1 exclusively.I have to approximate the differences between Brouncker's formula, and pi, and the preset value of the desired accuracy between the two. And print out how many times it went into the loop.

Python 3.2.2
The last line is to know what value the formula have so far in the loop

My code not working
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
Last Edited: 2012-01-24 18:50:57
January 24 2012 18:49 GMT
#2183
On January 25 2012 03:03 Lorac wrote:
I need to find the number of the formula within that precision of the real PI.

..what?

First: Speak english. "the precision of real pi" makes absolutely no sense. the "real pi" is an irrational number, it doesn't have a precision. Also you might want to link to the english wikipedia instead of the french. My french is a little .. no longer existent you know?

Second: Upload python code to pastebin.com for instance - anywhere really where the indentation is not stripped. Otherwise nobody can figure out your loops. ^^

R1ch should implement a [code] tag..
Gold isn't everything in life... you need wood, too!
silentsaint
Profile Joined September 2010
Germany540 Posts
January 24 2012 19:15 GMT
#2184
On January 25 2012 00:35 WerderBremen wrote:
I'm missing low level language - assembler. I got decent knowledge about programming on x8086 and a few other 16 bit models. Anybody else here who is programming with low level language (even others than assembler)? Would be interesting to know.


We did a little bit assembler in school and in the academy. Its not really existant at work where we mainly use C/C++, C#, Java or Perl depending on whats needed to be done.
Do you use Assembler at work or is it just a private infantuation?
It really tied the room together.
silentsaint
Profile Joined September 2010
Germany540 Posts
Last Edited: 2012-01-24 20:24:18
January 24 2012 20:23 GMT
#2185
On January 25 2012 03:03 Lorac wrote:
Hello I'm new to programming and I have to figure out an algorithm, the Formula of Brouncker for 4/pi William Brouncker

Sorry for the french because the english one doesn't show the right formula

I know how to do it on paper but it seems getting it into Python is a bit different so I could use some help :D
The user of the program as to input a precision value in real between 0 and 1 exclusively.I have to approximate the differences between Brouncker's formula, and pi, and the preset value of the desired accuracy between the two. And print out how many times it went into the loop.

Python 3.2.2
The last line is to know what value the formula have so far in the loop

My code not working


in your mid-part you do:

while (abs((((1+total)) - 4/pi)) >= x):

n = n / (((n+2)**2)) + 2
total = total + 2
n = n + 2
count = count + 1


Right there something is fundamentally wrong.
Why do you randomly increase n and total by 2?
That doesn't happen in the brouncker equation.

The problem with the brouncker equation is that the next step doesnt' add up to your current total just like that if you don't want it to be easymode. You would have to use recursion for the real solution.

Otherwise just use the rush-strategy:

while (abs((((total)) - 4/pi)) >= x):

if (n%2){
total = total + 1/(1+2*n);
}else{
total = total - 1/(1+2*n);
}
n = n+1

It really tied the room together.
Lorac
Profile Joined April 2010
Canada27 Posts
January 24 2012 21:18 GMT
#2186
On January 25 2012 05:23 silentsaint wrote:
Show nested quote +
On January 25 2012 03:03 Lorac wrote:
Hello I'm new to programming and I have to figure out an algorithm, the Formula of Brouncker for 4/pi William Brouncker

Sorry for the french because the english one doesn't show the right formula

I know how to do it on paper but it seems getting it into Python is a bit different so I could use some help :D
The user of the program as to input a precision value in real between 0 and 1 exclusively.I have to approximate the differences between Brouncker's formula, and pi, and the preset value of the desired accuracy between the two. And print out how many times it went into the loop.

Python 3.2.2
The last line is to know what value the formula have so far in the loop

My code not working


in your mid-part you do:

Show nested quote +
while (abs((((1+total)) - 4/pi)) >= x):

n = n / (((n+2)**2)) + 2
total = total + 2
n = n + 2
count = count + 1


Right there something is fundamentally wrong.
Why do you randomly increase n and total by 2?
That doesn't happen in the brouncker equation.

The problem with the brouncker equation is that the next step doesnt' add up to your current total just like that if you don't want it to be easymode. You would have to use recursion for the real solution.

Otherwise just use the rush-strategy:

while (abs((((total)) - 4/pi)) >= x):

if (n%2){
total = total + 1/(1+2*n);
}else{
total = total - 1/(1+2*n);
}
n = n+1




the brouncker works like that : 1+1^2/(2+3^2/(2+5^2/(2+7^2...........)))
so it adds 2 everytime
Lorac
Profile Joined April 2010
Canada27 Posts
Last Edited: 2012-01-25 05:31:47
January 25 2012 05:22 GMT
#2187
I did change a big my calculation of the formula and i came up with

v = ((1 + 2*n)**2) / (2 + v)

v being the last value

but now i want to tell him do this till n>=1 and i have to
v = 1 / (2 + v)
pib = (1 + v) pib is pi brounker

and i have to compare pib and pi and check if the precision i asked in the first input is good between both like 0.001 difference between both else n = n + 2

scarymeerkat
Profile Joined March 2011
Canada107 Posts
January 25 2012 19:55 GMT
#2188
I have a question about a program I recently wrote in C.

In it, I had a function that I wanted to do some operations on two specific indices in two different arrays. My first inclination was that I should write a function that looks like this:

int doSomethingWithArrays(int* array[1], int* otherArray[2]){
edit these values;
}

Obviously, that didn't work. But hopefully that communicates what I was trying to accomplish. In the end I ended up passing both the arrays and the specific indices as arguments. But that resulted in 4 arguments for my function. Is there a way to do what I was trying to do? (If you're confused, all I was trying to do is pass a pointer to an element in an array as an argument. )

Is this even possible? Or do I have a terribly flawed understand of what's going on?
"From... BootySmackarack" - Artosis reading GOM interview questions
Millitron
Profile Blog Joined August 2010
United States2611 Posts
January 25 2012 23:29 GMT
#2189
On January 26 2012 04:55 scarymeerkat wrote:
I have a question about a program I recently wrote in C.

In it, I had a function that I wanted to do some operations on two specific indices in two different arrays. My first inclination was that I should write a function that looks like this:

int doSomethingWithArrays(int* array[1], int* otherArray[2]){
edit these values;
}

Obviously, that didn't work. But hopefully that communicates what I was trying to accomplish. In the end I ended up passing both the arrays and the specific indices as arguments. But that resulted in 4 arguments for my function. Is there a way to do what I was trying to do? (If you're confused, all I was trying to do is pass a pointer to an element in an array as an argument. )

Is this even possible? Or do I have a terribly flawed understand of what's going on?

It depends. Is the function part of a class? For instance, if you create an object with the two arrays stored by the constructor, you can just pass the indices in the function.

If the function is not part of a class, then no, I think you're stuck with 4 arguments, unless you can hardcode the indices in the function, rather than passing them as parameters.
Who called in the fleet?
scarymeerkat
Profile Joined March 2011
Canada107 Posts
January 25 2012 23:39 GMT
#2190
.... that wouldn't be possible in C, would it? C isn't object-oriented. I didn't mean C++.

So I guess I'm stuck with 4 arguments and a lot of typing. So you for sure can't create a pointer to a member of an array like you would with a normal int?
"From... BootySmackarack" - Artosis reading GOM interview questions
Gak2
Profile Joined September 2010
Canada418 Posts
Last Edited: 2012-01-25 23:52:42
January 25 2012 23:43 GMT
#2191
On January 26 2012 08:39 scarymeerkat wrote:
.... that wouldn't be possible in C, would it? C isn't object-oriented. I didn't mean C++.

So I guess I'm stuck with 4 arguments and a lot of typing. So you for sure can't create a pointer to a member of an array like you would with a normal int?

you definitely can. I'm not completely sure, but try for example *(array+1) instead of *array[1]

EDIT: wait. scratch that. If you're creating the function, you should just use an int pointer (and call it whatever, just don't even mention it is an array value).

EDIT2: yeah see the guy who posted after me
heishe
Profile Blog Joined June 2009
Germany2284 Posts
January 25 2012 23:49 GMT
#2192
If you have an array of some type you can pass variables inside that array to a function like this:

+ Show Spoiler +

void someFunction(int *var)
{
//do whatever
}

//somewhere else
int array[someconstant] = {...whatever...};

someFunction(&array[your_index]);
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
scarymeerkat
Profile Joined March 2011
Canada107 Posts
Last Edited: 2012-01-26 00:02:07
January 25 2012 23:54 GMT
#2193
When I try *array[1] I get a compile time error: 42: error: invalid type argument of ‘unary *’ (have ‘int’)

In fact, not 100% sure because I forget how I might have changed the code while super tired last night, but I think what you were saying is what I had. I keep getting seg faults if I tinker with things til it compiles.

EDIT: thanks heishe, that works perfectly. definitely good to know. Ignore what I just said, everything works fine now.
"From... BootySmackarack" - Artosis reading GOM interview questions
Ninja_Bread
Profile Blog Joined August 2010
United States113 Posts
January 25 2012 23:57 GMT
#2194
Are you guys aware of a way to create dynamic structs, or create an unfixed number of strings during a program?
Mang
Sluggy
Profile Joined June 2010
United States128 Posts
January 26 2012 00:02 GMT
#2195
On January 26 2012 08:57 Ninja_Bread wrote:
Are you guys aware of a way to create dynamic structs, or create an unfixed number of strings during a program?


You mean an array whose size isn't fixed at runtime? In C/C++ it's malloc/new, in C#/java/python there are list collections you can use.
ranshaked
Profile Blog Joined August 2010
United States870 Posts
January 26 2012 02:45 GMT
#2196
Question: Write a complete C program that uses a FOR loop to read in 41 integers. For each of the 41 integers, first multiply the integer by itself; if the result obtained (ie the squared value) is greater than 500, the original integer (before it was squared) should be added into a sum that was initalized to zero. After the loop, multiply the sum by itself and then print out the answer as an integer. This is a review question for our test. I'm kind of stuck to be honest. It's not graded or anything, but there will be a similar question on the test tomorrow and I'd like to understand how/why this isn't working for me. I've put my notes in the // sections of the code

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

int main(void) {

int total;
int sum=0;
int number;

//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(number; number <=41; number++){
printf("What is your number\n");
scanf("%d", &number);}

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

total=sum*sum;

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

system("pause");
return 0;}


destian
Profile Joined August 2010
141 Posts
January 26 2012 03:23 GMT
#2197
On January 26 2012 11:45 ranshaked wrote:
Question: Write a complete C program that uses a FOR loop to read in 41 integers. For each of the 41 integers, first multiply the integer by itself; if the result obtained (ie the squared value) is greater than 500, the original integer (before it was squared) should be added into a sum that was initalized to zero. After the loop, multiply the sum by itself and then print out the answer as an integer. This is a review question for our test. I'm kind of stuck to be honest. It's not graded or anything, but there will be a similar question on the test tomorrow and I'd like to understand how/why this isn't working for me. I've put my notes in the // sections of the code

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

int main(void) {

int total;
int sum=0;
int number;

//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(number; number <=41; number++){
printf("What is your number\n");
scanf("%d", &number);}

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

total=sum*sum;

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

system("pause");
return 0;}




This seems like a bit too close to a homework question, so I'm going to just remark on a few things and let you figure out the rest.

First, you're using your loop variable as the user input variable. That is not correct.

Second, look at where your loop is ending, compared to the rest of the program logic.

Once you fix those two problems, review your usage of total and sum.
ranshaked
Profile Blog Joined August 2010
United States870 Posts
January 26 2012 03:54 GMT
#2198
On January 26 2012 12:23 destian wrote:
Show nested quote +
On January 26 2012 11:45 ranshaked wrote:
Question: Write a complete C program that uses a FOR loop to read in 41 integers. For each of the 41 integers, first multiply the integer by itself; if the result obtained (ie the squared value) is greater than 500, the original integer (before it was squared) should be added into a sum that was initalized to zero. After the loop, multiply the sum by itself and then print out the answer as an integer. This is a review question for our test. I'm kind of stuck to be honest. It's not graded or anything, but there will be a similar question on the test tomorrow and I'd like to understand how/why this isn't working for me. I've put my notes in the // sections of the code

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

int main(void) {

int total;
int sum=0;
int number;

//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(number; number <=41; number++){
printf("What is your number\n");
scanf("%d", &number);}

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

total=sum*sum;

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

system("pause");
return 0;}




This seems like a bit too close to a homework question, so I'm going to just remark on a few things and let you figure out the rest.

First, you're using your loop variable as the user input variable. That is not correct.

Second, look at where your loop is ending, compared to the rest of the program logic.

Once you fix those two problems, review your usage of total and sum.

It's not homework :/ just review for the exam...basically he gave us some problems to figure out for the test. I changed the variables, I didn't realize that the loop was the same. I'm using a different variable. I also changed the loop ending to right before the line "total=sum*sum" because that line is after the loop, but everytime I put in numbers I always get an answer of "0"
Kentor *
Profile Blog Joined December 2007
United States5784 Posts
Last Edited: 2012-01-26 04:31:58
January 26 2012 04:29 GMT
#2199
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;

Herper
Profile Joined January 2011
501 Posts
Last Edited: 2012-01-26 04:38:39
January 26 2012 04:37 GMT
#2200
On January 25 2012 03:49 MisterD wrote:
Show nested quote +
On January 25 2012 03:03 Lorac wrote:
I need to find the number of the formula within that precision of the real PI.

..what?

First: Speak english. "the precision of real pi" makes absolutely no sense. the "real pi" is an irrational number, it doesn't have a precision. Also you might want to link to the english wikipedia instead of the french. My french is a little .. no longer existent you know?

Second: Upload python code to pastebin.com for instance - anywhere really where the indentation is not stripped. Otherwise nobody can figure out your loops. ^^

R1ch should implement a [c0de] tag..


There is a [c0de] tag though....

public class CodeTagExample
{
public static void main(String[] args)
{
System.out.println("it werks!);
}
}


seems to break if you have more than one [c0de] tag that is not closed properly

Prev 1 108 109 110 111 112 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 3h 38m
[ Submit Event ]
Live Streams
Refresh
StarCraft: Brood War
Britney 16355
Larva 301
Mong 199
actioN 186
Nal_rA 89
Shuttle 75
Soma 47
Leta 46
Killer 42
zelot 34
[ Show more ]
ZergMaN 29
EffOrt 21
Bale 12
Dota 2
NeuroSwarm93
League of Legends
JimRising 563
C9.Mang0520
Counter-Strike
shoxiejesuss371
allub111
Super Smash Bros
Mew2King175
Other Games
summit1g8191
ceh9253
Sick183
Happy177
RuFF_SC231
Organizations
Other Games
gamesdonequick3157
StarCraft: Brood War
UltimateBattle 80
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• practicex 58
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• RayReign 51
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1535
• Stunt619
• masondota2416
• HappyZerGling153
Upcoming Events
WardiTV Invitational
3h 38m
PiGosaur Cup
16h 38m
WardiTV Invitational
1d 3h
The PondCast
2 days
OSC
2 days
OSC
3 days
All Star Teams
3 days
INnoVation vs soO
sOs vs Scarlett
uThermal 2v2 Circuit
4 days
All Star Teams
4 days
MMA vs DongRaeGu
Rogue vs Oliveira
Sparkling Tuna Cup
5 days
[ Show More ]
OSC
5 days
Replay Cast
6 days
Wardi Open
6 days
Liquipedia Results

Completed

Proleague 2026-01-12
Big Gabe Cup #3
NA Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
OSC Championship Season 13
Underdog Cup #3
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025

Upcoming

Escore Tournament S1: W4
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
Thunderfire SC2 All-star 2025
Nations Cup 2026
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
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 © 2026 TLnet. All Rights Reserved.