I’m trying to write simple code that will generate a random number from 10-99. And this number is supposed to be divided by 5. It works up until line 13.
using System;
namespace C_Test2
{
class Program1
{
static void Main(string[] args)
{
Random rnd = new Random();
for (int j = 0; j < 1; j++)
{
Console.WriteLine(rnd.Next(10, 99));
int h = 0;
int del = 5;
float h = j / del;
Console.WriteLine("Vores tal divideret med 5 er lig med: " + j);
}
}
}
}
But I’m having difficulty with the division part. I can’t get past boolean and int problem.
EDIT: Thanks everybody, I’m a beginner and the code posted was all I could perform with my current understanding and knowledge of coding. As said before edited gone, I’m new!
>Solution :
You hade some error:
-
variable h is declared two times
-
rnd.Next(10,99) never used
As I understand your problem this must be solution, just change the body of main methodRandom rnd = new Random(); for (int j = 0; j < 14; j++) { int randNr = rnd.Next(10, 99); Console.WriteLine(randNr); float del = 5; float result = randNr / del; Console.WriteLine("Vores tal divideret med 5 er lig med: " + result); }