Monday, January 27, 2014

currency conversion program functionality...please help!!!

Please post in code Blocks, it makes reading the code a lot easier. I repost your code for redability:



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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string userResponse = messageModule();
while (userResponse == "Yes")
{


inputModule();
conversionModule(inputModule());
outputModule(inputModule(), conversionModule(inputModule()));
Console.WriteLine("Do want to convert more money?Y/N");
userResponse = Console.ReadLine();
}

Console.WriteLine("Thanks and goodbye");


}
public static string messageModule()
{
string userResponse;
Console.WriteLine("You can convert Pesos, Eng Pounds, Euros, Yen, and Canadian dollars into U.S.\ndollars. Do you want to continue?Yes/No");
userResponse = Console.ReadLine();
return userResponse;

}
public static string inputModule()
{
string currencyType;
Console.WriteLine("Please enter the currency type that you want to convert?");
currencyType = Console.ReadLine();
Console.WriteLine("Is this the type of currency that you want to convert?Yes/No: " + currencyType);
string confirmation = Console.ReadLine();
while (confirmation == "No")
{
Console.WriteLine("Enter the currency that you want to convert.");
currencyType = Console.ReadLine();
Console.WriteLine("Is this the correct currency type?Yes/NO");
confirmation = Console.ReadLine();
}

return currencyType;
}
public static double conversionModule(string currencyTypeToBeConverted)
{
double euros = 0.7676;
double EngPound = 1.6433;
double Pesos = 9.5085;
double Yen = 104.9200;
double CanDollars = 1.4690;


double amountInForeignDollars;
double amountInUSDollars = 0;
string userResponse;
Console.WriteLine("Please enter the amount of " + currencyTypeToBeConverted + " that you want converted into U.S. dollars");
amountInForeignDollars = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Are you sure that you want to convert this amount: " + amountInForeignDollars);
Console.WriteLine("From " + currencyTypeToBeConverted + " to U.S. dollars?Y/N");
userResponse = Console.ReadLine();
while (userResponse != "Y")
{
Console.WriteLine("Please enter the correct amount");
amountInForeignDollars = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Is this the correct amount?Y/N" + amountInForeignDollars);
userResponse = Console.ReadLine();
}
if(currencyTypeToBeConverted == "Euros")
{
amountInUSDollars = amountInForeignDollars * euros;
}
else if(currencyTypeToBeConverted == "Eng Pound")
{
amountInUSDollars = amountInForeignDollars * EngPound;
}
else if(currencyTypeToBeConverted == "Pesos")
{
amountInUSDollars = amountInForeignDollars * Pesos;
}
else if(currencyTypeToBeConverted =="Yen")
{
amountInUSDollars = amountInForeignDollars * Yen;
}
else if (currencyTypeToBeConverted == "Canadian dollars")
{
amountInUSDollars = amountInForeignDollars * CanDollars;
}

return amountInUSDollars;
}
public static void outputModule(string currencyType, double amountUSDollars)
{
Console.WriteLine("The amount of money in " + currencyType);
Console.WriteLine("Is " + amountUSDollars);
}


}
}

Please specify wich part you "have to repeat" and in wich case. From lapheal's reply I figure it is the Input Module:



conversionModule(inputModule());
outputModule(inputModule(), conversionModule(inputModule()));

The reason is that you call it twice, instead of calling it once and storing the result in a varriable.


Side Notes:


Module is not an ideal name for a function, consider naming it Function instead.


The ideal construct for 'console input loops' is the do...while loop (it solves the "run at least once" problem):

http://ift.tt/1mN4Rx2




Let's talk about MVVM: http://ift.tt/1fpEgna Please mark post as helpfull and answers respectively.



No comments:

Post a Comment