hello,
Below is the program written to enter item description, price and date of purchase. finally it is going to give the total amount.
here i wanted to write the output of this program to a file created and saved on the desktop .To create a file, i have used
StreamWriter fileWriter = new StreamWriter("groceries.txt");
fileWriter.Close();so ,here a text file is created on the desktop. after that,
The output of the program should be written to this text file. to write to the text file i have used
string text = "ram";
System.IO.File.WriteAllText(@"C:\Users\ram\desktop\groceries.txt", text);
for trial purpose i am trying to write text ram into the file created by me(groceries.txt). Its working .
But i want the output of this console application to be written into groceries.txt File. any clue how to proceed?
as this is my first program any clue will be really helpful.
thanks in advance
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string Description;
float price,totalcost=0;
DateTime dt;
int key;
do
{
Console.Write("enter the item:");
Description = Console.ReadLine();
Console.Write("enter the date of purchase:");
dt = DateTime.Parse(Console.ReadLine());
Console.Write("enter the amount:");
price = float.Parse(Console.ReadLine());
totalcost += price;
Console.Write("the total expenditure is:");
Console.WriteLine(totalcost);
Console.WriteLine("press key value to continue");
key = int.Parse(Console.ReadLine());
} while (key != 0);
StreamWriter fileWriter = new StreamWriter("groceries.txt");
fileWriter.Close();
string text = "ram";
System.IO.File.WriteAllText(@"C:\Users\ram\desktop\groceries.txt", text);
Console.Read();
}
}
}