• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:50
CEST 03:50
KST 10:50
  • 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
[ASL20] Ro8 Preview Pt1: Mile High11Team TLMC #5 - Finalists & Open Tournaments2[ASL20] Ro16 Preview Pt2: Turbulence10Classic Games #3: Rogue vs Serral at BlizzCon10[ASL20] Ro16 Preview Pt1: Ascent10
Community News
StarCraft II 5.0.15 PTR Patch Notes192BSL 2025 Warsaw LAN + Legends Showmatch2Weekly Cups (Sept 8-14): herO & MaxPax split cups4WardiTV TL Team Map Contest #5 Tournaments1SC4ALL $6,000 Open LAN in Philadelphia8
StarCraft 2
General
StarCraft II 5.0.15 PTR Patch Notes Why Storm Should NOT Be Nerfed – A Core Part of Pr #1: Maru - Greatest Players of All Time SC4ALL: A North American StarCraft LAN Team TLMC #5 - Finalists & Open Tournaments
Tourneys
RSL: Revival, a new crowdfunded tournament series SC2's Safe House 2 - October 18 & 19 Stellar Fest KSL Week 80 StarCraft Evolution League (SC Evo Biweekly)
Strategy
Custom Maps
External Content
Mutation # 492 Get Out More Mutation # 491 Night Drive Mutation # 490 Masters of Midnight Mutation # 489 Bannable Offense
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ Old rep packs of BW legends ASL ro8 Upper Bracket HYPE VIDEO [ASL20] Ro8 Preview Pt1: Mile High BW General Discussion
Tourneys
[ASL20] Ro16 Group D SC4ALL $1,500 Open Bracket LAN BSL 2025 Warsaw LAN + Legends Showmatch [ASL20] Ro16 Group C
Strategy
Simple Questions, Simple Answers Muta micro map competition
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Borderlands 3 General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
Community
General
US Politics Mega-thread The Big Programming Thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread UK Politics Mega-thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023
World Cup 2022
Tech Support
Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s)
TL Community
BarCraft in Tokyo Japan for ASL Season5 Final The Automated Ban List
Blogs
Why can't Americans stop ea…
Peanutsc
Too Many LANs? Tournament Ov…
TrAiDoS
I <=> 9
KrillinFromwales
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1671 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 8h 10m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
NeuroSwarm 143
RuFF_SC2 109
StarCraft: Brood War
Artosis 849
Sharp 38
NaDa 16
Dota 2
capcasts372
League of Legends
Cuddl3bear4
Heroes of the Storm
Khaldor160
Other Games
summit1g10287
JimRising 544
C9.Mang0218
Maynarde136
Mew2King38
Organizations
Other Games
gamesdonequick694
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• Berry_CruncH237
• davetesta34
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Upcoming Events
Afreeca Starleague
8h 10m
Barracks vs Mini
Wardi Open
9h 10m
Monday Night Weeklies
14h 10m
Sparkling Tuna Cup
1d 8h
Afreeca Starleague
1d 8h
Snow vs EffOrt
PiGosaur Monday
1d 22h
LiuLi Cup
2 days
The PondCast
3 days
CranKy Ducklings
4 days
Maestros of the Game
5 days
Clem vs Reynor
[ Show More ]
[BSL 2025] Weekly
5 days
[BSL 2025] Weekly
5 days
BSL Team Wars
6 days
Liquipedia Results

Completed

2025 Chongqing Offline CUP
RSL Revival: Season 2
HCC Europe

Ongoing

BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
Maestros of the Game
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

Upcoming

IPSL Winter 2025-26
SC4ALL: Brood War
BSL 21 Team A
BSL Season 21
Stellar Fest
SC4ALL: StarCraft II
EC S1
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
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.