How to allow user to input new values in an if statement - c#

I would like for someone to help me by telling me what code I should use in case the input number turns out to be for the second if or third if, if the user doesn't put the right amount (73-77) then id like the user to be able to type in a new value I can use... how do I do that please?
namespace test
{
class Program
{
public static int FahrToCels(int fahr)
{
int cel = (fahr - 32) * 5 / 9;
return cel;
}
static void Main(string[] args)
{
Console.WriteLine("write down temprature: ");
int fahrenheit = int.Parse(Console.ReadLine());
int celsius = FahrToCels(fahrenheit);
Console.Write("Press any key to continue . . .");
Console.ReadKey(true);
do
if (celsius >= 73 && celsius <= 77)
{
Console.WriteLine("now it works ");
}
else if (celsius < 72)
{
Console.WriteLine("");
}
else if (celsius > 77)
{
Console.WriteLine("");
}
while (true);
}
}
}

There are a few major issues with what you have. Attached is working code for what I believe you are looking for, though in your ifs you have Celsius range in the 70s when the point of your Fahrenheit to Celsius converter turns the value into Celsius which would lie in the 20s range.
namespace test
{
class Program
{
public static int FahrToCels(int fahr)
{
int cel = (fahr - 32) * 5 / 9;
return cel;
}
static void Main(string[] args)
{
int celsius;
int fahrenheit;
do
{
Console.WriteLine("Skrive in Temperaturen: ");
fahrenheit = int.Parse(Console.ReadLine());
celsius = FahrToCels(fahrenheit);
Console.Write("Presifs any key to continue . . .");
Console.ReadKey(true);
if (celsius >= 22 && celsius <= 28)
{
Console.WriteLine("now it works ");
//Insert whatever here
break;
}
else if (celsius < 22)
{
//Something to tell them they need to retry
}
else if (celsius > 28)
{
//Something to tell them they need to retry
}
}
while (celsius >= 22 && celsius <= 28);
}
}
}
I would recommend changing the range on your ifs to the values you want the user to input, and also provide the user with some error/retry statement in your elseifs. Also would recommend instead of having two elseifs just use else. Also would remove that stupid readkey() in my opinion.
If you have any questions to my answer leave them in the comments.

If you want to ensure that celsius is in [73..77] range you can try
static void Main(string[] args) {
int fahrenheit;
int celsius;
// Keep asking user until (s)he enters a valid celsius value
while (true) {
Console.WriteLine("Skrive in Temperaturen: ");
// check if value a valid integer, and not say "bla-bla-bla"
if (!int.TryParse(Console.ReadLine(), out fahrenheit)) {
Console.WriteLine("Not an integer value, please, try again");
continue;
}
// fahrenheit is a valid integer value, we can compute corresponding celsius...
celsius = FahrToCels(fahrenheit);
// ... and validate the celsius value then
if (celsius < 73)
Console.WriteLine("Too low temperature (below 73 degree Celsius)");
else if (celsius > 77)
Console.WriteLine("Too high temperature (above 77 degree Celsius)");
else
break; // celsius is valid integer value in [73..77] range
}
// From now on celsius contains integer in [73..77] range
Console.WriteLine("Now it works");
Console.Write("Press any key to continue . . .");
Console.ReadKey(true);
}

Related

how do i activate the other loop (if /else if)

Im having problem with a program that takes farenheight translates it to celsius and tells you if the temperature is too low or too high.
Right now the to low part works but for some reason the loop doesn't work when it's to high.
using System;
namespace Bastun2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter temperature");
double temperatureF = double.NaN;
if (double.TryParse(Console.ReadLine(), out temperatureF) && temperatureF < 163.4)
{
Console.WriteLine($"{temperatureF}°F is to low, enter a higher temperature");
}
//double temperatureC = (temperatureF - 32) * 5 / 9;
//Console.WriteLine($"{temperatureF}°F, {temperatureC}°C");
else if (double.TryParse(Console.ReadLine(), out temperatureF) && temperatureF > 170.6)
{
Console.WriteLine($"{temperatureF} °F is to high, enter a lower temperature");
}
double temperatureC = (temperatureF - 32) * 5 / 9;
Console.WriteLine($"{temperatureF}°F, {temperatureC}°C");
}
}
}
You don't have any loop here.
Store the result of Console.ReadLine() in a variable like so :
double temperatureF = double.NaN;
double.TryParse(Console.ReadLine(), out temperatureF);
And replace where you used Console.ReadLine() previously by temperatureF.
You are reading two times from the console. After your first check failed, the user has to input another value so the second check can happen.
You should only read the input once and store it in a varibale. Then you can check on that variable.
You could also use a loop, so the user does not have too restart the program until he enters a valid input.
static void Main(string[] args)
{
double temperatureF = double.NaN;
string input = string.Empty;
bool inputIsOkay = false;
while(!inputIsOkay)
{
Console.WriteLine("Enter temperature");
input = Console.ReadLine();
if (!double.TryParse(input, out temperatureF))
{
Console.WriteLine($"'{input}' is not a valid input...");
}
else if (temperatureF < 163.4)
{
Console.WriteLine($"{temperatureF}°F is to low, enter a higher temperature");
}
else if (temperatureF > 170.6)
{
Console.WriteLine($"{temperatureF} °F is to high, enter a lower temperature");
}
else
{
inputIsOkay = true;
}
}
double temperatureC = (temperatureF - 32) * 5 / 9;
Console.WriteLine($"{temperatureF}°F, {temperatureC}°C");
Console.ReadKey();
}

Temperature converter

Im am trying to solve an issue.
My teacher wants us to do a C# console with temperature converter from Celsius to Fahrenheit and switch. The problem is I continue getting errors in my coding and I don't know where I started wrong in order to get completely lost. Just to mention I am in the beginning and I would appreciate some help.
We should write a program that displays a list of temperatures in Celsius converted to Fahrenheit and vice versa. A menu is provided for the user to choose the type of conversions: The menu should repeat until the user chooses 0 to exit.
When option 1 is chosen, the program calculates and displays a list of values between 0 and 212 degrees in Fahrenheit converted to Celsius degrees as shown in the next image When option 2 is selected, the program lists values from 0 to 100 Celsius converted to Fahrenheit degrees.
This is my beginning:
using System;
namespace TempconverterA2
{
class TemperatureConverter
{
public void Start()
{
Console.WriteLine("**************************************");
Console.WriteLine("\t MAIN MENU");
Console.WriteLine("**************************************");
Console.WriteLine(" Convert Fahrenheit to Celsius : 1");
Console.WriteLine(" Convert Celsius to Farenheit : 2");
Console.WriteLine(" Exit the Converter : 0");
Console.WriteLine("**************************************");
Console.WriteLine("\nYour choice: ");
switch (choice)
{
case 1:
CalculateFarenheitToCelsius(F = 9 / 5 * C + 32);
break;
case 2:
CalculateCelsiusToFarenhet(C = 5 / 9 * (F - 32));
case 0: //do nothing (exists to loop)
break;
default:
Console.WriteLine("Invalid option. Choose between 0 and 2.");
break;
} while (choice != 0) ;
public void CalculateCelsiusToFarenhet()
{
double convertedValue = 0;
stringtextOut = string.Empty;
for (int i= 0, i <= 100; i += 5)
{
convertedValue = CalculateCelsiusToFarenhet(i);
textOut = string.Format("{0,16:f2} C = {1,6:f2} F", i, convertedValue);
Console.WriteLine(textOut);
}
Console.WriteLine();
}
}//End of Start
This is not doing what you think it is:
switch (choice)
{
// case statements removed for brevity
} while (choice != 0);
It is actually doing this:
switch (choice)
{
}
while (choice != 0)
{
// infinite loop if choice != 0
}
This is because switch is a control block and while is a separate control block.

Keeping numbers in a range

I am attempting to get some data validation done but I am really struggling with that. I have been using If statements and was hoping If (pun intended) someone could help me. I am very new to the whole thing and have a massive piece that needs to be done so far I have managed but this got me stumped. I really would like a push or something in the correct direction because it feels like I am rubbing my head against a piece of sandpaper
int iNumber1;
int iNumber2;
Console.WriteLine("Please give me 2 number between -10 and +10 and ill add them together");
Console.Write("Please enter a number: ");
iNumber1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter a number: ");
iNumber2 = Convert.ToInt32(Console.ReadLine());
int iResult;
//here i get the adding bit done
iResult = iNumber1 + iNumber2;
//bool bUserInput = false;
//while (!bUserInput)
//{
// string sInput = Console.ReadLine();
// if (iNumber1 < -10)
// {
// Console.WriteLine("Your are out of range please stay between -10 and +10");
// }
// if (iNumber1 < 10)
// {
// Console.WriteLine("Your are out of range please stay between -10 and +10 ");
// }
// if (iNumber2 < -10)
// {
// Console.WriteLine("Your are out of range please stay between -10 and +10");
// }
// if (iNumber2 < 10)
// {
// Console.WriteLine("Your are out of range please stay between -10 and +10");
// }
//}
if (iResult <= -10 || iResult >= 11)
{
Console.WriteLine("Out of range calculation is ignored");
}
else
{
Console.WriteLine("That number is vaild and its {0}", iResult);
}
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Please give me 2 number between -10 and +10 and ill add them together\n");
int iNumber1 = readNumber();
int iNumber2 = readNumber();
int iResult = iNumber1 + iNumber2;
Console.WriteLine("The sum of {0} + {1} is {2}", iNumber1, iNumber2, iResult);
}
//you should use functions to avoid code repetition.
//the function below reads the user input and tries to convert it into a number.
//the validation rule is applied inside the loop.
private static int readNumber()
{
bool bUserInput;
int number;
//below is a loop that runs at least once. the loop continues
//iterating while the condition evaluates to true, otherwise it ends
//and control goes to the statement immediately after it.
do
{
Console.WriteLine("Please enter a number: ");
//Int32.TryParse receives as arguments a string to parse and
//an integer as an output argument (you need the out keyword)
//it returns true if it the string could be successfully converted
//into an integer and false if it couldn't.
bUserInput = Int32.TryParse(Console.ReadLine(), out number);
if (!bUserInput)//this will be true if the user input could not be converted
{
Console.WriteLine("Input could not be converted into an integer number");
//the continue statement is used inside a loop to skip the rest of it
//and jump directly to the test condition
continue;
}
if (number < -10 || number > 10)//the validation
{
//the error message
Console.WriteLine("Your are out of range please stay between -10 and +10");
//make sure we set the flag to false because in this case,
//Int32.TryParse has set it to true, but input is still invalid
//by the validation rules.
bUserInput = false;
}
else//the number is in range, set the flag to true
{
Console.WriteLine("Good Job!\n");
//set the flag to true, so the loop can end.
bUserInput = true;
}
}while(!bUserInput);//while this evaluates to true, the loop continues.
return number;
}
}
So you need a way to validate that a number is between -10 and +10 (inclusive). That should be easy:
bool isValid(int i)
{
return (i >= -10) && (i <= 10);
}
now you need a function to see if two numbers are both valid:
bool areValid(int i1, int i2)
{
return isValid(i1) && isValid(i2);
}
Now just assume that input is not valid, and loop until it is:
bool isValid = false;
while(!isValid)
{
Console.WriteLine("Please give me 2 number between -10 and +10 and I'll add them together");
Console.Write("Please enter a number: ");
iNumber1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter a number: ");
iNumber2 = Convert.ToInt32(Console.ReadLine());
isValid = areValid(iNumber1, iNumber2);
if(!isValid)
{
Console.WriteLine("Out of range calculation is ignored");
}
}
Now you know you have two valid numbers and can continue with the rest of your program.

How to reloop the game and ask something

I made a program that calculates the temperature in different ways.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Excercise_7
{
class Program
{
static void Main(string[] args)
{
showBegin();
decide();
secondPlay();
showEnd();
}
// Decide code
static void decide() {
int choice;
string input;
input = Console.ReadLine();
int.TryParse(input, out choice);
if (choice == 1)
{
Console.WriteLine("");
celciusSystem();
}
else if (choice == 2)
{
Console.WriteLine("");
farenheitSystem();
}
else if (choice == 3)
{
Console.WriteLine("");
kelvinSystem();
}
else {
Console.WriteLine("");
Console.WriteLine("Make sure u write a number between 1 and 3! No text!");
Console.WriteLine("");
showBegin();
decide();
}
}
static void secondPlay()
{
int choice2;
string input;
Console.WriteLine("");
Console.WriteLine("Type 1 to play again, type 2 to close the application");
input = Console.ReadLine();
int.TryParse(input, out choice2);
}
// Begin code
static void showBegin()
{
Console.WriteLine("Welcom at the temperature calculator, pick the mode u prefer!");
Console.WriteLine("Press 1 for Celcius mode");
Console.WriteLine("Press 2 for Fahrenheit mode");
Console.WriteLine("Press 3 for Kelvin mode");
Console.WriteLine("Press the correct number and then hit the enter button!");
Console.WriteLine("");
}
// Temperature Calculators
static void celciusSystem()
{
Console.WriteLine("This is the Celsius calculator");
Console.Write("Enter the amount of celsius: ");
int celsius = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("");
Console.WriteLine("The temperature in Kelvin = {0}", celsius + 273);
Console.WriteLine("The temperature in Fahrenheit = {0}", celsius * 18 / 10 + 32);
}
static void farenheitSystem()
{
Console.WriteLine("This is the Fahrenheit calculator");
Console.Write("Enter the amount of Fahrenheit: ");
int Fahrenheit = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("");
Console.WriteLine("The temperature in Kelvin = {0}", (Fahrenheit + 459.67) / 1.8);
Console.WriteLine("The temperature in Celsius = {0}", (Fahrenheit - 32) / 1.8);
}
static void kelvinSystem()
{
Console.WriteLine("This is the Kelvin calculator");
Console.Write("Enter the amount of Kelvin: ");
int Kelvin = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("");
Console.WriteLine("The temperature in Fahrenheit = {0}", Kelvin * 1.8 - 459.67);
Console.WriteLine("The temperature in Celsius = {0}", Kelvin - 273.15);
}
// End code
static void showEnd()
{
Console.WriteLine("");
Console.WriteLine("We hoped u enjoyed our application!");
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}
}
}
So now my question, I made a class called second play. Within that class i tried to make a kind a statement that would ask the user if he or she wanted to "play" again. So if they write 1 he should loop the game again.
I have tried it with this
if (choice2 == 1)
{
while (choice2 == 1) {
Console.WriteLine("");
showBegin();
decide();
}
}
else {
Console.WriteLine("");
Console.WriteLine("Cheers!!");
}
}
then he actually worked but not the way I wanted to because if the user writes 1 it will loop the first thing all over again. So the user can't quit the game any more.
I want the application to ask after every trail if he or she wants to play again by typing 1 or 2.
You already know how to read lines from the console, you also know how to use if to compare booleans, so why don't you just apply this and check if they wrote a 1 or 2?
private bool playAgain()
{
int number = 2; //Invalid option: close game
Int32.TryParse(Console.ReadLine(), out number);
if (number == 1)
{
return true;
}
else if (number == 2)
{
return false;
}
else
{
Console.WriteLine("Unknown option, quitting!");
return false;
}
}
Then you just have to use that function to determine if they want to play again in a do-loop.
static void Main(string[] args)
{
showBegin(); //Show begin sequence
do
{
decide();
secondPlay();
} while(playAgain()); //Play again if they want to
showEnd(); //Show end sequence when they decided not to play
}
Pro tip: use a switch-case statement instead of multiple if-else statements.
You can use a do while loop, which serves you well in cases like yours, when you want to execute your loop at least once:
do {
Console.WriteLine("");
showBegin();
decide();
//Ask for choice2 here
}
while(choice2 == 1);
Console.WriteLine("");
Console.WriteLine("Cheers!!");
To enter game loop, it is most useful to start with simple while or do-while.
while( conditionToRun )
{
//run the program
if( userWantToExit )
conditionToRun = false;
}
Or
do
{
// run the program
} while ( !userWantToExit )
This code shows the most basic stuff to handle this.
To apply on Your game/program, use:
static void Main(string[] args)
{
bool userWantToEnd = false;
showBegin();
while( !userWantToEnd)
{
decide();
userWantToEnd = IsUserWillingToContinue();
}
showEnd();
}
And adjust the SecondPlay() method into something like IsUserWillingToContinue():
public bool IsUserWillingToContinue()
{
int choice2;
string input;
Console.WriteLine("");
Console.WriteLine("Type 1 to play again, type 2 to close the application");
input = Console.ReadLine();
int.TryParse(input, out choice2);
return choice2 == 1;
}
Adding more info based on comment of #devRicher - You should split up a bit the code so it work in this way
bool runAgain = true;
Console.WriteLine("Begin info: (Hello this is XY game.)");
while(runAgain)
{
Console.WriteLine("You have 3 options: 1, 2, 3");
PickOptionAndRunTheCode();
bool runAgain = DoYouWantToContinue();
Console.Clear(); // clear the Console screen (next time You will see only options, not the text on first run).
}
I would recommend to get more knowledge about games to go to this page -> http://gameprogrammingpatterns.com/ (and read the book)
Check this pattern: Game Loop

simple temperature conversion questions

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConTempConversion_LeeMichelle
{
class Program
{
static void Main(string[] args)
{
double fTemp;
double cTemp;
double convertC;
double convertF;
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("_________________________________________________");
Console.WriteLine("1. Fahrenheit to Celsius");
Console.WriteLine("2. Celsius to Fahrenheit");
Console.WriteLine("3. Exit");
Console.Write("Enter choice: ");
Console.ReadKey();
int ichoice = 0;
do
{
if (ichoice == 1)
{
Console.WriteLine("Enter Fahrenheit temperature: ");
fTemp = int.Parse(Console.ReadLine());
convertC = ConvertCelcius(fTemp);
Console.WriteLine(fTemp + "Fahrenheit is " + convertC + "Celsius");
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("_________________________________________________");
Console.ReadKey();
}
if (ichoice == 2)
{
Console.WriteLine("Enter Celsius temperature: ");
cTemp = int.Parse(Console.ReadLine());
convertF = ConvertFahrenheit(cTemp);
Console.WriteLine(cTemp + "Celsius is " + convertF + "Fahrenheit");
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("____________________________________________________");
Console.ReadKey();
}
if (ichoice == 3)
{
Console.WriteLine("Thank you for using the temperature conversion application. Please come again.");
}
else
{
Console.WriteLine("Invalid choice. Please choose again!");
}
}
while (ichoice > 3);
Console.ReadKey();
}
static double ConvertCelcius(double c){
double f;
return f= 9.0 / 5.0 * c + 32;
}
static double ConvertFahrenheit(double f) {
double c;
return c = 5.0 / 9.0 * (f - 32);
}
}
}
so suppose the user has three options from 1 - 3. After option 3, there will be an error alert. my problem is why this code gives me an infinity loop? what did I do wrong? can I put break after each if statment?
Please help, thank you!
You're creating a do...while loop without anything to ever exit it. When the loop begins, ichoice is already set in stone. So you'll always be stuck in that loop!
You are never assigning a value to ichoice If I were you, I would try something like this:
int ichoice = 0;
int.TryParse(Console.ReadKey().ToString(), out ichoice );
do
{
if (ichoice == 1)
{
Console.WriteLine("Enter Fahrenheit temperature: ");
fTemp = int.Parse(Console.ReadLine());
convertC = ConvertCelcius(fTemp);
Console.WriteLine(fTemp + "Fahrenheit is " + convertC + "Celsius");
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("_________________________________________________");
int.TryParse(Console.ReadKey().ToString(), out ichoice );
Add the int.TryParse(Console.ReadKey().ToString(), out ichoice ); everywhere you have Console.Readline(). What this is doing is getting the user input and converting it to an integer (if it's not an integer, then the value is 0).
Also add this:
if (ichoice == 3)
{
Console.WriteLine("Thank you for using the temperature conversion application. Please come again.");
break;
}
else
{
Console.WriteLine("Invalid choice. Please choose again!");
int.TryParse(Console.ReadKey().ToString(), out ichoice );
}
Finally, remove this (I'm not quite sure what it was for...)
while (ichoice > 3);
Console.ReadKey();
When you need to do some prep work before your condition, the most straightforward way involves combining your loop with a separate structure.
This is the format to use when your loop condition is at the beginning of the loop:
prep work
while (condition) // if false then loop body will never run
{
loop body
}
This is the format to use when the loop condition is at the end of the loop:
prep work
do
{
loop body
}
while (condition); // loop body will always execute at least once
In this case, you have some prep work to do before each iteration--you want to get the key press from the user each time. For this, I recommend the following from Code Complete:
while (true) // loop termination condition is inside the loop
{
prep work
if (condition)
{
break;
}
loop body
}
In your case, it would look something like:
Console.Write("Enter choice: ");
while (true) // loop termination condition is inside the loop
{
Console.ReadKey();
if (ichoice == 3)
{
Console.WriteLine(...);
break;
}
...
}
Also, consider changing most of your ifs into else ifs; otherwise, you're repeatedly checking the condition even when you've gone through one case.
you should assign a value to iChoice. and set your while to read a terminating character. like:
namespace YourNameSpace
{
static void Main(string[] args)
{
double fTemp;
double cTemp;
double convertC;
double convertF;
int iChoice;
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("_________________________________________________");
Console.WriteLine("1. Fahrenheit to Celsius");
Console.WriteLine("2. Celsius to Fahrenheit");
Console.Write("Enter choice(0 to exit): ");
iChoice = Console.Read();
do{
switch(iChoice)
{
case 1:
Console.WriteLine("Enter Fahrenheit temperature: ");
fTemp = int.Parse(Console.ReadLine());
convertC = ConvertCelcius(fTemp);
Console.WriteLine(fTemp + "Fahrenheit is " + convertC + "Celsius");
case 2:
Console.WriteLine("Enter Celsius temperature: ");
cTemp = int.Parse(Console.ReadLine());
convertF = ConvertFahrenheit(cTemp);
Console.WriteLine(cTemp + "Celsius is " + convertF + "Fahrenheit");
}
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("_________________________________________________");
Console.WriteLine("1. Fahrenheit to Celsius");
Console.WriteLine("2. Celsius to Fahrenheit");
Console.Write("Enter choice(0 to exit): ");
iChoice = Console.Read();
}while(iChoice != 0);
}
static double ConvertCelcius(double c){
double f;
return f= 9.0 / 5.0 * c + 32;
}
static double ConvertFahrenheit(double f) {
double c;
return c = 5.0 / 9.0 * (f - 32);
}
}
Each time you call Console.ReadKey you should store returning value.You are receiving input from user but you didn't store it anywhere.
First you can create a function to get ichoice, and force user to enter the correct value:
static void GetChoice(ref int ichoice)
{
string input = Console.ReadLine();
Console.Write("Enter choice: ");
bool result = int.TryParse(input, out ichoice);
if (!result)
{
while (!result && ichoice > 3)
{
Console.WriteLine("Invalid value.Try again:");
input = Console.ReadLine();
result = int.TryParse(input, out ichoice);
}
}
}
Then use this function whenever you need to make a choice.
Here is the working version or your program:
double fTemp;
double cTemp;
double convertC;
double convertF;
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("_________________________________________________");
Console.WriteLine("1. Fahrenheit to Celsius");
Console.WriteLine("2. Celsius to Fahrenheit");
Console.WriteLine("3. Exit");
int ichoice = 0;
GetChoice(ref ichoice);
do
{
if (ichoice == 1)
{
Console.WriteLine("Enter Fahrenheit temperature: ");
fTemp = int.Parse(Console.ReadLine());
convertC = ConvertCelcius(fTemp);
Console.WriteLine(fTemp + "Fahrenheit is " + convertC + "Celsius");
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("_________________________________________________");
GetChoice(ref ichoice);
}
if (ichoice == 2)
{
Console.WriteLine("Enter Celsius temperature: ");
cTemp = int.Parse(Console.ReadLine());
Console.WriteLine(cTemp + "Celsius is " + cTemp + "Fahrenheit");
Console.WriteLine("Welcome to the temperature conversion application");
Console.WriteLine("____________________________________________________");
GetChoice(ref ichoice);
}
if (ichoice == 3)
{
Console.WriteLine("Thank you for using the temperature conversion application. Please come again.");
}
else
{
Console.WriteLine("Invalid choice. Please choose again!");
}
}
while (ichoice < 3);
}
static double ConvertCelcius(double c)
{
double f;
return f = 9.0 / 5.0 * c + 32;
}
static double ConvertFahrenheit(double f)
{
double c;
return c = 5.0 / 9.0 * (f - 32);
}
And here is the full code: http://pastebin.com/bkegSAFL

Categories