Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problems with simple code generating rnd number which is divided by 5

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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 method

     Random 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);
         }
    
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading