Today I'm having trouble with something basic and just having a complete lapse trying to remember how to do this. What I'm trying to do is simply use a number from a file as the int variable for my whole program. Using C#.

StreamReader read = new StreamReader("../../data.dat");
string input=(Console.ReadLine());
int num = Convert.ToInt32(input);
System.Console.WriteLine("Range of Numbers: 1 - " + num);

for (int i = 1; i <= num; i++)
{
    if (DivBySeven(i) == true && DivByEleven(i) == true)
    {
        int j = i;
        while (j > 0)
        {
            System.Console.Write("@ ");
            j--;
        }
    }
    else if (DivBySeven(i) == true)
    {
        System.Console.Write("* ");
    }
    else if (DivByEleven(i) == true)
    {
        System.Console.Write(". ");
    }
    else
    {
        System.Console.Write(i +" ");
    }
}

Console.ReadKey();

Sorry for the lack of comments. Quick overview: I am taking the number from the file and using it to output to the console 1-the file number, and taking multiples of 11 and 7, also just 7 and just 11 and doing a couple different things with them.

有帮助吗?

解决方案

You have

string input=(Console.ReadLine());  // read from the keyboard
int num = Convert.ToInt32(input);

which is user keyboard input.

To read from the file you need

string input=(read.ReadLine());  // read from the stream reader
int num = Convert.ToInt32(input);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top