|
-
January 3rd, 2012, 01:29 AM
#1
Having trouble building this converter without using goto
I am trying to have a statement within my cases inside my switch to send the program back to the start if the user inputs they want to continue and ends the program with goodbye if they say no. I don't understand how to backtrack to the beginning of the program without using goto.
Code:
using System;
namespace CSharp_Lesson_1_4_Practice
{
class Program
{
static void Main()
{
// The purpose of this program is to create a temperature converter from Celius to Fareinheit and vice versa.
string sInput1;
int iInput1;
string sInput2;
float iInput2;
float ftemp;
float ctemp;
string eval;
do
{
Console.WriteLine("This program converts temperatures between Celsius and Fahrenheit.\n");
Console.WriteLine("Which do you want to convert:");
Console.WriteLine("1. Celsius to Fahrenheit");
Console.WriteLine("2. Fahrenheit to Celsius\n");
Console.Write("Enter 1 or 2 for your choice: ");
sInput1 = Console.ReadLine();
iInput1 = Int32.Parse(sInput1);
// Console.WriteLine(" {0}", iInput1);
switch (iInput1)
{
case 1:
Console.Write("Enter the temperature in Celcius so I can covnert it to Fahrenheit for you: ");
sInput2 = Console.ReadLine();
iInput2 = float.Parse(sInput2);
ftemp = (float)iInput2 * (float)1.8 + (float)32;
Console.Write("The temperature from Celcius to Farenheit is: {0}", ftemp);
Console.ReadLine();
do
{
Console.Write("Do you want to continue? ");
eval = Console.ReadLine();
} while (eval != "yes");
break;
case 2:
Console.Write("Enter the temperature in Fahrenheit so I can convert it to Celcius for you: ");
sInput2 = Console.ReadLine();
iInput2 = float.Parse(sInput2);
ctemp = ((float)iInput2 - (float)32) / (float)1.8;
Console.Write("The temperature from Farenheit to Celcius is: {0}", ctemp);
Console.ReadLine();
do
{
Console.Write("Do you want to continue? ");
eval = Console.ReadLine();
} while (eval != "yes");
break;
}
} while (iInput1 != 1 && iInput1 != 2);
Console.WriteLine("Goodbye!!!");
Console.ReadLine();
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|