116k views
1 vote
Hello! I am a new coder, so this is a simple question. But I am trying to create a code where you enter a number, then another number, and it divides then multiply the numbers. I put both numbers as a string, and as result when i tried to multiply/divide the numbers that were entered, an error occurred. How can i fix this?

using System;

namespace Percentage_of_a_number
{
class Program
{
static object Main(string[] args)
{
Console.WriteLine("Enter percentage here");
string Percentage = Console.ReadLine();


Console.WriteLine("Enter your number here");
string Number = Console.ReadLine();

String Result = Percentage / 100 * Number;


}
}
}

User Chnet
by
3.6k points

1 Answer

4 votes

no longer returns an error but your math seems to have something wrong with it, always returns 0

Console.WriteLine("Enter a percentage here");

int Percent = int.Parse(Console.ReadLine());

Console.WriteLine("Enter your number here");

int Number = int.Parse(Console.ReadLine());

int result = Percent / 100 * Number;

User Mircea
by
4.3k points