Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Need some help with C#


  • Please log in to reply
2 replies to this topic

#1 Uraiser

Uraiser

  • Members
  • 254 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:San Antonio, TX
  • Local time:01:08 PM

Posted 09 February 2009 - 10:07 PM

I'm new to C#, and I'm doing my 3rd assignment with it. The purpose of this program is for the user to input a number of eggs for 4 chickens, then at the end, the program will calculate how many eggs there are total, and how many dozens there are total. I've gotten the code to allow for user input, and to write the line after the user inputs the number. When it gets to the final step, the total is blank. Can someone take a look at my code and point me in the right direction?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Eggs
{
	class Program
	{
		static void Main(string[] args)
		{
			
			
			Console.WriteLine("This program shows the number of eggs produced by 4 chickens in one month.");//
			int num1;
			Console.WriteLine("Enter the Egg Number for Chicken 1: ");
			num1 = Convert.ToInt32(Console.ReadLine());
			Console.WriteLine("Chicken 1 Layed {0} Eggs", num1);
			
			int num2;
			Console.WriteLine("Enter the Egg Number for Chicken 2: ");
			num2 = Convert.ToInt32(Console.ReadLine());
			Console.WriteLine("Chicken 2 Layed {0} Eggs", num1);
			
			int num3;
			Console.WriteLine("Enter the Egg Number for Chicken 3: ");
			num3 = Convert.ToInt32(Console.ReadLine());
			Console.WriteLine("Chicken 3 Layed {0} Eggs", num3);
			
			int num4;
			Console.WriteLine("Enter the Egg Number for Chicken 4: ");
			num4 = Convert.ToInt32(Console.ReadLine());
			Console.WriteLine("Chicken 4 Layed {0} Eggs", num4);

			int total = num1 + num2 + num3 + num4;
			total = Convert.ToInt32(Console.ReadLine());
			Console.WriteLine("The Total Egg count is {0}", total);



		}
	}
}


BC AdBot (Login to Remove)

 


#2 Uraiser

Uraiser
  • Topic Starter

  • Members
  • 254 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:San Antonio, TX
  • Local time:01:08 PM

Posted 09 February 2009 - 10:16 PM

Nevermind, I discovered the solution. I needed to remove
total = Convert.ToInt32(Console.ReadLine());
from the final statement.

#3 Uraiser

Uraiser
  • Topic Starter

  • Members
  • 254 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:San Antonio, TX
  • Local time:01:08 PM

Posted 09 February 2009 - 11:30 PM

AAANNND the final product, if anyone is interested.
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;



namespace Eggs

{

	class Program

	{

		static void Main(string[] args)

		{

			

			

			Console.WriteLine("This program shows the number of eggs produced by 4 chickens in one month.");//

			int num1;

			Console.WriteLine("Enter the Egg Number for Chicken 1: ");

			num1 = Convert.ToInt32(Console.ReadLine());

			Console.WriteLine("Chicken 1 Layed {0} Eggs", num1);

			

			int num2;

			Console.WriteLine("Enter the Egg Number for Chicken 2: ");

			num2 = Convert.ToInt32(Console.ReadLine());

			Console.WriteLine("Chicken 2 Layed {0} Eggs", num1);

			

			int num3;

			Console.WriteLine("Enter the Egg Number for Chicken 3: ");

			num3 = Convert.ToInt32(Console.ReadLine());

			Console.WriteLine("Chicken 3 Layed {0} Eggs", num3);

			

			int num4;

			Console.WriteLine("Enter the Egg Number for Chicken 4: ");

			num4 = Convert.ToInt32(Console.ReadLine());

			Console.WriteLine("Chicken 4 Layed {0} Eggs", num4);



			int total = num1 + num2 + num3 + num4;



			Console.WriteLine("The Total Egg count is {0}", total);

			int dozen = 12;



			int totaldoz = (num1 + num2 + num3 + num4) / dozen; 

				int remainder = total % dozen;

			Console.WriteLine("The Total Dozens of eggs is {0} with {1} extra", totaldoz, remainder);







		}

	}

}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users