Hey, I'm working on this project and I need to know how to use global variables, basically, I have three functions, one of which sets the data for the other functions to use. In my main, I want to call all these functions to work.
using System.IO;
using System;
namespace Assignment
{
class MainClass
{
public static void FileOpen()
{
// create an char array containing grades
int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
// open the new text file
TextReader tr = new StreamReader("/Users//Desktop/Assignmenty/grades.dat");
string line;
while ((line = tr.ReadLine()) != null)
{
if(line == "A")
{
a++;
}else if(line == "B")
{
b++;
}else if(line == "C")
{
c++;
}else if(line == "D")
{
d++;
}else if(line == "E")
{
e++;
}else if(line == "F")
{
f++;
}
}
Graph(a, b, c, d, e, f);
}
public static void WebPage (int gradeA, int gradeB, int gradeC, int gradeD, int gradeE, int gradeF)
{
TextWriter tw = new StreamWriter ("grades,html");
string line = "<html><head><title>Grades: Calculator</title></head><body><b>HELLO</b></body>";
tw.WriteLine(line);
tw.Close();
}
public static void Graph(int gradeA, int gradeB, int gradeC, int gradeD, int gradeE, int gradeF)
{
Console.WriteLine ("0\t10\t20\t30\t40\t50\t60\t70\t80\t90\t100");
Console.WriteLine ("|\t|\t|\t|\t|\t|\t|\t|\t|\t|\t|");
Console.WriteLine ("*********************************************************************************");
int resultA = gradeA * 100 / 50;
int resultB = gradeB * 100 / 50;
int resultC = gradeC * 100 / 50;
int resultD = gradeD * 100 / 50;
int resultE = gradeE * 100 / 50;
int resultF = gradeF * 100 / 50;
Console.WriteLine (resultA);
Console.WriteLine (resultB);
Console.WriteLine (resultC);
Console.WriteLine (resultD);
Console.WriteLine (resultE);
Console.WriteLine (resultF);
}
public static void Main (string[] args)
{
Console.Clear();
FileOpen();
WebPage(a, b, c, d, e, f); // This function will not call.
}
}
}
The other thing is that i want to create some HTML code and then write it into the file. The only problem is that I don't want to have it inside the code, I want to display it externally and then add it in. Is there a way of including files like in C++?
Best regards.