C# - Tryinig to do exchange rates in if/else statement and pass argument into method parameters in main function -


i trying use method calculate exchange rate pass argument method in main. unsure if have converted money cant figure out put parameters when calling method in main.

for example: exchange(dont know put here);

also unsure if have done exchange method correctly. program runs point of asking currency user whats exchange to, thats when comment out exchange method. stuck, tips?

i think might have assign values each of currencies sek, usd ,eur not sure there...

any appreciated!

(if have enetered code wrong on question im sorry, not sure how make cleaner)

----this console application----

class program {     static void main(string[] args)     {         writemenu();         //exchange();         //exchange(choicefromcurrency, coicetocurrency, valuetoexchange);         console.readkey();     }      public static void writemenu()     {         console.writeline("welcome next level currency converter!");         console.writeline("---we---change---your---money---for---you---");         console.writeline(" -------so---you---dont---have---to!-------\n\n");          console.writeline("what base currency?\n");         console.writeline("1 = sek, 2= usd or 3= eur?");         string userinput = console.readline();          if (userinput == "1")         {             console.writeline("you have chosen sek (swedish krona)\n");          }         else if (userinput == "2")         {             console.writeline("you have chosen usd (united states dollar)\n");         }         else         {             console.writeline("you have chosen eur (euro)\n");         }          console.writeline("which currency change money to?\n");         string userinput2 = console.readline();         if (userinput2 == "1")         {             console.writeline("you have chosen sek (swedish krona)\n");         }         else if (userinput2 == "2")         {             console.writeline("you have chosen usd (united states dollar)\n");         }         else         {             console.writeline("you have chosen eur (euro)\n");         }      }      public static decimal exchange(decimal currencytoexchangefrom, decimal currencytoexchangeto )     {         console.writeline("how exchange?\n");         string amounttoexchange = console.readline();         decimal amounttoconvert = 0;         decimal.tryparse(amounttoexchange, out amounttoconvert);         decimal newvalue;          // sek         if(currencytoexchangefrom == 1)         {             // sek - sek             if (currencytoexchangeto == 1)             {                  console.writeline("you have money, go spend it!");              }              // sek -usd             if (currencytoexchangeto == 2)             {                 newvalue = amounttoconvert / 8.50m;                 console.writeline("you have" + newvalue + " in usd");              }         }         //sek - eur         if(currencytoexchangefrom == 2)         {             amounttoconvert / 9.49m;             console.writeline("you have" + newvalue + " in eur");          }         //  usd - eur         if (currencytoexchangefrom == 3)         {             amounttoconvert * 0.90m;             console.writeline("you have" + newvalue + " in eur");         } 

here's ideas going... have feeling homework, i've done modest re-working.

static void main(string[] args)     {         begin();         console.readline();     }     public static void begin()     {         console.writeline("welcome next level currency converter!");         console.writeline("---we---change---your---money---for---you---");         console.writeline(" -------so---you---dont---have---to!-------\n\n");          console.writeline("what base currency?\n");         console.writeline("1 = sek, 2= usd or 3= eur?");         consolekeyinfo keypress = console.readkey(true);         int uconvertfrom = getuserinput(keypress);         if (uconvertfrom > -1)         {             switch (uconvertfrom)             {                 case 1:                     console.writeline("you have chosen sek (swedish krona)\n");                      break;                 case 2:                     console.writeline("you have chosen usd (united states dollar)\n");                      break;                 case 3:                     console.writeline("you have chosen eur (euro)\n");                      break;              }          }         else         {             if (uconvertfrom == -2)             {                 //break;             }             else             {                 console.writeline("you didn't enter valid response. please try again");                 begin();             }         }         console.writeline("which currency change money to?\n");         keypress = console.readkey(true);         int uconvertto = getuserinput(keypress);         if (uconvertto > -1) {             switch (uconvertto)             {                 case 1:                     console.writeline("you have chosen sek (swedish krona)\n");                     break;                 case 2:                     console.writeline("you have chosen sek (swedish krona)\n");                     break;                 case 3:                     console.writeline("you have chosen usd (united states dollar)\n");                     break;                 case 4:                     console.writeline("you have chosen eur (euro)\n");                     break;             }          }         else         {             if (uconvertfrom == -2)             {                 //break;             }             else             {                 console.writeline("you didn't enter valid response. please try again");                 begin();             }         }         exchange((decimal)uconvertfrom, (decimal)uconvertto);     }     private static int getuserinput(consolekeyinfo keypress)     {         if (keypress.key == consolekey.escape)         {             console.writeline("thank using. exiting now.");             return -2;         }         int ret = -1;         if (int.tryparse(keypress.keychar.tostring(), out ret))         {              return ret;         }         else         {              return -1;         }     }     public static decimal exchange(decimal currencytoexchangefrom, decimal currencytoexchangeto)     {         console.writeline("how exchange?\n");         string amounttoexchange = console.readline();         decimal amounttoconvert = 0;         decimal.tryparse(amounttoexchange, out amounttoconvert);         decimal newvalue = (decimal)0.000;          // sek         if (currencytoexchangefrom == 1)         {             // sek - sek             if (currencytoexchangeto == 1)             {                  console.writeline("you have money, go spend it!");              }              // sek -usd             if (currencytoexchangeto == 2)             {                 newvalue = amounttoconvert / 8.50m;                 console.writeline("you have" + newvalue.tostring("c2") + " in usd");              }         }         //sek - eur         if (currencytoexchangefrom == 2)         {             amounttoconvert /= 9.49m;             console.writeline("you have" + newvalue.tostring("c2") + " in eur");          }         //  usd - eur         if (currencytoexchangefrom == 3)         {             amounttoconvert *= 0.90m;             console.writeline("you have" + newvalue.tostring("c2") + " in eur");         }         return (decimal).001;     } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -