0
I’m solving an exercise in which it is necessary to declare an employee’s number, how many hours he works and how much he earns per hour, then the system must display this employee’s number and salary, the problem is that the result should be displayed with dots instead of comma in the decimal place, my code so far is this:
using System;
using System.Globalization;
class URI
{
static void Main(string[] args)
{
int numeroFunc, horasTrabalhadas;
decimal valorHora;
numeroFunc = int.Parse(Console.ReadLine());
horasTrabalhadas = int.Parse(Console.ReadLine());
valorHora = decimal.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
Console.WriteLine("NUMBER = " + numeroFunc);
Console.WriteLine("SALARY = U$ " + (horasTrabalhadas * valorHora));
Console.ReadLine();
}
I know I could solve the problem by creating a salary variable to receive the value of timesWork * valueHora and use the command Console.WriteLine("SALARY = U$ " + salario.ToString("F2", CultureInfo.InvariantCulture));
to display the message with points, but the exercise asks that no other variables are created than those requested.
When converting the reading, your code can generate an exception. Use Tryparce instead of Parse. int32.Tryparse(Console.Readline(), out numeroFunc);
– Roberto De Almeida