Jump to content

http://pastebin.com/gFn2zSXT

 

In the for loop part when trying to have it stop when placement is less than 10. It continues and displays 16 which is the 2^4.

 

Thanks,

Case: NZXT Phantom Green Trim   Graphics Card: EVGA GTX 670 2gb FTW    CPU: Intel i7 4770k 3.5GHZ    Motherboard: Gigabyte G1 Sniper 5   Hard Drives: One Western Digital 1TB & Hitachi 1TB   Power Supply: Corsair RM 850w

 

Cooler: Corsair H80i Liquid Cooler    Ram: Corsair Vengeance 2x4gb & Mushkin 1x4gb   Monitors: Two Asus 22'' 1080p monitors   Keyboard: CM Storm Quickfire XT Green   Mouse: Razer Naga 2014   Microphone:  Audio- Technica AT2020 XLR with a Alesis MultiMix 4   Headphones: Sennheiser HD 280 Pro

Link to comment
https://linustechtips.com/topic/232687-mathpow-problem-c/
Share on other sites

Link to post
Share on other sites

The issue is that it increments before the loop ends. 

 

It will print placement = 8 (2^3) then it will itterate pt to 4. it will run through the loop, set placement =16 (2^4), then print it, then it leaves the loop as 16 !< 10.

 

On a side note, just for the sake of clarity, I would just initizlize double pt and double placement without assigning any values.

 		static void Main(string[] args)			        {			           string numPeoplestr = "Enter the number of people in the group";			           double numPeople = 10;			           double pt; placement; 			 			           double[] pa = new double[10];			 			           for ( pt = 1;  placement < 10; pt++)			           {			 			               placement = Math.Pow(2, pt);			               Console.WriteLine(placement);			 			           }			}			

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
https://linustechtips.com/topic/232687-mathpow-problem-c/#findComment-3180427
Share on other sites

Link to post
Share on other sites

Is there anyway that I can have it stop before it gets the value of sixteen while still using the powers of 2.

Case: NZXT Phantom Green Trim   Graphics Card: EVGA GTX 670 2gb FTW    CPU: Intel i7 4770k 3.5GHZ    Motherboard: Gigabyte G1 Sniper 5   Hard Drives: One Western Digital 1TB & Hitachi 1TB   Power Supply: Corsair RM 850w

 

Cooler: Corsair H80i Liquid Cooler    Ram: Corsair Vengeance 2x4gb & Mushkin 1x4gb   Monitors: Two Asus 22'' 1080p monitors   Keyboard: CM Storm Quickfire XT Green   Mouse: Razer Naga 2014   Microphone:  Audio- Technica AT2020 XLR with a Alesis MultiMix 4   Headphones: Sennheiser HD 280 Pro

Link to comment
https://linustechtips.com/topic/232687-mathpow-problem-c/#findComment-3180568
Share on other sites

Link to post
Share on other sites

Is there anyway that I can have it stop before it gets the value of sixteen while still using the powers of 2.

 

You could use a do while loop instead of a for loop. That way it'll check the condition at the end of the loop instead of the start.

double pt = 1;double placement = 0;do {    placement = Math.Pow(2, pt);    Console.WriteLine(placement);    pt++;} while (placement < 10)
Link to comment
https://linustechtips.com/topic/232687-mathpow-problem-c/#findComment-3180712
Share on other sites

Link to post
Share on other sites

Hmm I some how figured it out by reordering it the the write line and placement equals. http://pastebin.com/gFn2zSXT

 

Edit:

Nevermind it did this instead 2, 2, 4, 6, 8.

Case: NZXT Phantom Green Trim   Graphics Card: EVGA GTX 670 2gb FTW    CPU: Intel i7 4770k 3.5GHZ    Motherboard: Gigabyte G1 Sniper 5   Hard Drives: One Western Digital 1TB & Hitachi 1TB   Power Supply: Corsair RM 850w

 

Cooler: Corsair H80i Liquid Cooler    Ram: Corsair Vengeance 2x4gb & Mushkin 1x4gb   Monitors: Two Asus 22'' 1080p monitors   Keyboard: CM Storm Quickfire XT Green   Mouse: Razer Naga 2014   Microphone:  Audio- Technica AT2020 XLR with a Alesis MultiMix 4   Headphones: Sennheiser HD 280 Pro

Link to comment
https://linustechtips.com/topic/232687-mathpow-problem-c/#findComment-3180820
Share on other sites

Link to post
Share on other sites

Also how did you put the body of code in your reply instead of doing something like pastebin?

Case: NZXT Phantom Green Trim   Graphics Card: EVGA GTX 670 2gb FTW    CPU: Intel i7 4770k 3.5GHZ    Motherboard: Gigabyte G1 Sniper 5   Hard Drives: One Western Digital 1TB & Hitachi 1TB   Power Supply: Corsair RM 850w

 

Cooler: Corsair H80i Liquid Cooler    Ram: Corsair Vengeance 2x4gb & Mushkin 1x4gb   Monitors: Two Asus 22'' 1080p monitors   Keyboard: CM Storm Quickfire XT Green   Mouse: Razer Naga 2014   Microphone:  Audio- Technica AT2020 XLR with a Alesis MultiMix 4   Headphones: Sennheiser HD 280 Pro

Link to comment
https://linustechtips.com/topic/232687-mathpow-problem-c/#findComment-3180826
Share on other sites

Link to post
Share on other sites

Hmm I some how figured it out by reordering it the the write line and placement equals. http://pastebin.com/gFn2zSXT

 

Edit:

Nevermind it did this instead 2, 2, 4, 6, 8.

 

 

After the first call to 

double placement = Math.Pow(2, pt);

You don't increment pt. Your loop needs to be started at 2 instead of 1.

Link to comment
https://linustechtips.com/topic/232687-mathpow-problem-c/#findComment-3181473
Share on other sites

Link to post
Share on other sites

Nevermind I figured it out. Probably a janky way but whatever.

Case: NZXT Phantom Green Trim   Graphics Card: EVGA GTX 670 2gb FTW    CPU: Intel i7 4770k 3.5GHZ    Motherboard: Gigabyte G1 Sniper 5   Hard Drives: One Western Digital 1TB & Hitachi 1TB   Power Supply: Corsair RM 850w

 

Cooler: Corsair H80i Liquid Cooler    Ram: Corsair Vengeance 2x4gb & Mushkin 1x4gb   Monitors: Two Asus 22'' 1080p monitors   Keyboard: CM Storm Quickfire XT Green   Mouse: Razer Naga 2014   Microphone:  Audio- Technica AT2020 XLR with a Alesis MultiMix 4   Headphones: Sennheiser HD 280 Pro

Link to comment
https://linustechtips.com/topic/232687-mathpow-problem-c/#findComment-3200175
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×