Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   New to the forum, need a bit of help/guidance re C# (http://www.programmingforums.org/showthread.php?t=11930)

DC_FC79 Nov 18th, 2006 6:29 AM

New to the forum, need a bit of help/guidance re C#
 
I have to write a program using C# for an assignment,

basically the program must work out the amount tat each person should pay towards a tea kitty each week. Each person drinks drinks drinks a day. 1 pint of milk makes 1 drinks, the teabags come in boxes of 480 teabags(1 teabag makes 1 drink) and the bag of sugar is used to make 100 drinks.

i obviously declare the variables at the start i got that bit but its the rest of the program

I just dont know where to start(im not askin for someone to do it for me but for some pointers),

Id appreciate your help alot,

Arevos Nov 18th, 2006 6:43 AM

Well, it's simple arithmetic, no? Write down the equations you'd use to calculate it manually, and then convert them into C# code.

DC_FC79 Nov 18th, 2006 6:46 AM

ok so i do the calculations but its how to write it into the program, what lines of code to use

are there any sites i can have a look at for a quick tutorial on C#

Polyphemus_ Nov 18th, 2006 6:55 AM

Use Google.

I think it's rather weird that you have to write a program for an assignment, and you don't even know how to do simple arithmetics.

Arevos Nov 18th, 2006 7:10 AM

Well, I'll give you an example similar to your problem. Lets say you want to create a program that converts Fahrenheit into degrees Celsius. It might look something like this:
:

  1. using System;
  2.  
  3. namespace Example
  4. {
  5.     class FahrenheitCelsiusConverter
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             // Get input from the user
  10.             Console.WriteLine("Enter a temperature in Fahrenheit");
  11.             string userInput = Console.ReadLine();
  12.  
  13.             // Convert user input into a number
  14.             double fahrenheit;
  15.             try
  16.             {
  17.                 fahrenheit = double.Parse(userInput);
  18.             }
  19.             // If the user entered something that wasn't a number
  20.             // then complain and exit
  21.             catch (FormatException)
  22.             {
  23.                 Console.WriteLine("Invalid input. Exiting!");
  24.                 return;
  25.             }
  26.  
  27.             // Convert fahrenheit to celsius using an equation
  28.             double celsius = (fahrenheit - 32) / 1.8;
  29.  
  30.             Console.WriteLine("The temperature in Celsius is " + celsius);
  31.         }
  32.     }
  33. }

Note that "double" is a type of number in C# that can have decimal places. If you only need whole numbers (i.e. integers), then you can use "int" instead.

DC_FC79 Nov 18th, 2006 8:02 AM

Quote:

Originally Posted by Polyphemus_ (Post 119222)
Use Google.

I think it's rather weird that you have to write a program for an assignment, and you don't even know how to do simple arithmetics.

i can do the arithmetics no problem, the fact is that all this C# has gone over my head,

DC_FC79 Nov 18th, 2006 8:07 AM

Quote:

Originally Posted by Arevos (Post 119223)
Well, I'll give you an example similar to your problem. Lets say you want to create a program that converts Fahrenheit into degrees Celsius. It might look something like this:
:

  1. using System;
  2.  
  3. namespace Example
  4. {
  5.     class FahrenheitCelsiusConverter
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             // Get input from the user
  10.             Console.WriteLine("Enter a temperature in Fahrenheit");
  11.             string userInput = Console.ReadLine();
  12.  
  13.             // Convert user input into a number
  14.             double fahrenheit;
  15.             try
  16.             {
  17.                 fahrenheit = double.Parse(userInput);
  18.             }
  19.             // If the user entered something that wasn't a number
  20.             // then complain and exit
  21.             catch (FormatException)
  22.             {
  23.                 Console.WriteLine("Invalid input. Exiting!");
  24.                 return;
  25.             }
  26.  
  27.             // Convert fahrenheit to celsius using an equation
  28.             double celsius = (fahrenheit - 32) / 1.8;
  29.  
  30.             Console.WriteLine("The temperature in Celsius is " + celsius);
  31.         }
  32.     }
  33. }

Note that "double" is a type of number in C# that can have decimal places. If you only need whole numbers (i.e. integers), then you can use "int" instead.

Arevos

ill have a go at changing the bits necessary for me

Arevos Nov 18th, 2006 8:25 AM

Quote:

Originally Posted by DC_FC79 (Post 119226)
ill have a go at changing the bits necessary for me

Er... I'd have preferred it if you had said something more like, "That's helped me understand how C# works," rather than, "I'll copy the structure of your code without necessarily understanding how it works."

Samuaijack Nov 18th, 2006 11:19 AM

Have you ever write any thing in C# before ????

crawforddavid2006 Nov 18th, 2006 1:26 PM

Quote:

Originally Posted by Arevos (Post 119223)
Well, I'll give you an example similar to your problem. Lets say you want to create a program that converts Fahrenheit into degrees Celsius. It might look something like this:
:

  1. using System;
  2.  
  3. namespace Example
  4. {
  5.     class FahrenheitCelsiusConverter
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             // Get input from the user
  10.             Console.WriteLine("Enter a temperature in Fahrenheit");
  11.             string userInput = Console.ReadLine();
  12.  
  13.             // Convert user input into a number
  14.             double fahrenheit;
  15.             try
  16.             {
  17.                 fahrenheit = double.Parse(userInput);
  18.             }
  19.             // If the user entered something that wasn't a number
  20.             // then complain and exit
  21.             catch (FormatException)
  22.             {
  23.                 Console.WriteLine("Invalid input. Exiting!");
  24.                 return;
  25.             }
  26.  
  27.             // Convert fahrenheit to celsius using an equation
  28.             double celsius = (fahrenheit - 32) / 1.8;
  29.  
  30.             Console.WriteLine("The temperature in Celsius is " + celsius);
  31.         }
  32.     }
  33. }

Note that "double" is a type of number in C# that can have decimal places. If you only need whole numbers (i.e. integers), then you can use "int" instead.

Hey we don't do homework unless they have shown an obvious effort towards the assignment.


All times are GMT -5. The time now is 1:37 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC