8 Replies - 665 Views - Last Post: 29 April 2009 - 03:43 PM Rate Topic: -----

#1 ctreed728  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-April 09

Doubling Penny

Post icon  Posted 29 April 2009 - 02:16 PM

I am supposed to show a penny doubling for a month. I am able to show the day (1-30) but am having trouble displaying the penny starting from .01 and doubling for 30 days. Any help would be appreciated. There are no errors with the following code (but it is messed up.)


using System;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main(string[] args)
		{

			int counter = 0;
			decimal penny = .01M;
			string result = "";

			Console.WriteLine("\n\n		Day	 $$$");

			while (counter < 30)
			{
				counter++;
				penny++;
				result += " \t"
					+ counter
					+ " \t"
					+ penny * 2
					+" \n";
			}

			Console.WriteLine(result);
		}
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Doubling Penny

#2 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Doubling Penny

Posted 29 April 2009 - 02:58 PM

View Postctreed728, on 29 Apr, 2009 - 01:16 PM, said:

I am supposed to show a penny doubling for a month. I am able to show the day (1-30) but am having trouble displaying the penny starting from .01 and doubling for 30 days. Any help would be appreciated. There are no errors with the following code (but it is messed up.)


using System;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main(string[] args)
		{

			int counter = 0;
			decimal penny = .01M;
			string result = "";

			Console.WriteLine("\n\n		Day	 $$$");

			while (counter < 30)
			{
				counter++;
				penny++;
				result += " \t"
					+ counter
					+ " \t"
					+ penny * 2
					+" \n";
			}

			Console.WriteLine(result);
		}
	}
}



Instead of

penny++;



you need

penny *= 2;



and remove * 2 from the other statement with penny in it.
Was This Post Helpful? 0
  • +
  • -

#3 ctreed728  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-April 09

Re: Doubling Penny

Posted 29 April 2009 - 03:03 PM

Oh my gosh. Thanks. I thought I already tried something like that but I probably didn't remove the * 2 over something like that.

What if I need to start with .01 at Day 1. Right now the code says:

Day $$$
1 0.02
Was This Post Helpful? 0
  • +
  • -

#4 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Doubling Penny

Posted 29 April 2009 - 03:08 PM

View Postctreed728, on 29 Apr, 2009 - 02:03 PM, said:

Oh my gosh. Thanks. I thought I already tried something like that but I probably didn't remove the * 2 over something like that.

What if I need to start with .01 at Day 1. Right now the code says:

Day $$$
1 0.02


Move where you double the penny after where you have result += that should fix it.
Was This Post Helpful? 0
  • +
  • -

#5 ctreed728  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-April 09

Re: Doubling Penny

Posted 29 April 2009 - 03:20 PM

Hmm....where exactly? If I put it right after, the program won't work right and it says to be a ";" somewhere. I doubt you meant RIGHT after it.
Was This Post Helpful? 0
  • +
  • -

#6 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Doubling Penny

Posted 29 April 2009 - 03:34 PM

				counter++;
				result += " \t"
					+ counter
					+ " \t"
					+ penny
					+" \n";
				penny *= 2;



Try that.

(If I helped you you could click the link ;))
Was This Post Helpful? 1
  • +
  • -

#7 ctreed728  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-April 09

Re: Doubling Penny

Posted 29 April 2009 - 03:39 PM

Thank you. That worked perfectly. Hopefully I will get the hang of this. lol
Was This Post Helpful? 0
  • +
  • -

#8 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: Doubling Penny

Posted 29 April 2009 - 03:42 PM

View Postctreed728, on 29 Apr, 2009 - 02:39 PM, said:

Thank you. That worked perfectly. Hopefully I will get the hang of this. lol


It takes time and practice. Try thinking of simple programs and try and figure out how to do them. Determining if a number is a prime number is a good one. Factorials is another good one.
Was This Post Helpful? 0
  • +
  • -

#9 ctreed728  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-April 09

Re: Doubling Penny

Posted 29 April 2009 - 03:43 PM

Ok cool. The factorial one sounds pretty interesting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1