VisHal ChOuhan

VisHal ChOuhan

  • NA
  • 1
  • 788

How to Sava Data in C# to use that when I restart Program

Oct 23 2016 12:27 PM
I have a program using which I calculate Net RunRate of cricket matches. I want this program to save data so that when I restart the program it starts from where I left. For now I have this program for 2 matches only. I would like to Use this to calculate Net RunRate of a team who plays 9 matches in a tournament. So my need is when the team plays its first match I calculate its Net RunRate and the program save this data and when that team plays its second match I need to calculate its NRR again so I need the program to store the first data and start directly from the second match. I am a beginner so my code is little bit lengthy.
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NRR
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to Net Run Rate Calculator");
//Console.WriteLine("Enter Zero for Runs & Overs if Match is not Played");
//First Innings
Console.Write("Runs Scored By Team?(Till Now): ");
var first = Double.Parse(Console.ReadLine());
Console.Write("Runs Scored By Team?(Current Match): ");
var second = Double.Parse(Console.ReadLine());
/*Console.Write("Runs Scored By Team?(3rd Match): ");
var third = Double.Parse(Console.ReadLine());*/
var runsScored = first + second;
Console.WriteLine("Total Runs Scored: " +runsScored);
Console.Write("Number of Overs Faced?(Till Now): ");
var oversFirst = Double.Parse(Console.ReadLine());
Console.Write("Number of Overs Faced?(Current Match) , 10 if all Out: ");
var oversSecond = Double.Parse(Console.ReadLine());

/* Console.Write("Number of Overs Faced?(3rd Match) , 10 if all Out: ");
var oversThird = Double.Parse(Console.ReadLine());*/
var oversTaken = oversFirst + oversSecond;
Console.WriteLine("Total Overs Taken: " + oversTaken);
var firstInningsTotal = runsScored / oversTaken;
Console.WriteLine("RunRate= " + firstInningsTotal);
//Second Innings
Console.Write("Runs Scored by Opponent(Till Now): ");
var secFirst = Double.Parse(Console.ReadLine());
Console.Write("Runs Scored by Opponet(Current Match): ");
var secSecond = Double.Parse(Console.ReadLine());
/*Console.Write("Runs Scored by Opponent(3rd Match): ");
var secThird = Double.Parse(Console.ReadLine());*/
var runsScoredOpponent = secFirst + secSecond;
Console.WriteLine("Total Runs Scored by the Opponent: " + runsScoredOpponent);
Console.Write("Number of Overs Faced?(Till Now) ");
var overSecFirst = Double.Parse(Console.ReadLine());
Console.Write("Number of Overs Faced?(Current Match) 10 if all Out: ");
var overSecSecond = Double.Parse(Console.ReadLine());
/*Console.Write("Number of Overs Faced?(Third Match) 10 if all Out: ");
var overSecThird = Double.Parse(Console.ReadLine());*/
var overTakenSecond = overSecFirst + overSecSecond;
Console.WriteLine("Total Overs Taken by Opponent: " +overTakenSecond);
var secondInningsTotal = runsScoredOpponent / overTakenSecond;
Console.WriteLine("Opponent's RunRate= " + secondInningsTotal);
var Total = firstInningsTotal - secondInningsTotal;
var newTotal = secondInningsTotal - firstInningsTotal;

Console.WriteLine("Net RunRate of Required Team Is:"+ Total);
//Console.WriteLine("Net RunRate of Opponent is:" + newTotal);
Console.ReadLine();
}
}
}
 

Answers (1)