Skip to content

Instantly share code, notes, and snippets.

@musoftware
Created December 5, 2014 22:39
Show Gist options
  • Select an option

  • Save musoftware/9f76ffce8b4eca2276f9 to your computer and use it in GitHub Desktop.

Select an option

Save musoftware/9f76ffce8b4eca2276f9 to your computer and use it in GitHub Desktop.
More User Input of Data
//Please enter the details:
//First name:
//Last name:
//Grade(9-12):
//Student Id:
//Username:
//GPA(0.0-4.0):
//Plex
//Vera
//9
//12345
//Plexy182
//3.3
//Your Information:
//Username:Plexy182
//Id:12345
//Name:Vera Plex
//GPA:3.3
//Grade:9
using System;
using System.Linq;
class Program
{
static void Main()
{
try
{
var firstName = "";
var lastName = "";
var grade = 0;
var studentId = 0;
var login = "";
var gpa = 0.0;
Console.WriteLine("Please enter the details:\n");
Console.WriteLine("First name:");
firstName = Console.ReadLine();
Console.WriteLine("Last name:");
lastName = Console.ReadLine();
r:
Console.WriteLine("Grade(9-12):");
if (!int.TryParse(Console.ReadLine(), out grade) | !(grade >= 9 & grade <= 12)) goto r;
r2:
Console.WriteLine("Student Id:");
if (!int.TryParse(Console.ReadLine(), out studentId)) goto r2;
Console.WriteLine("Username:");
login = Console.ReadLine();
r3:
Console.WriteLine("GPA(0.0-4.0):");
if (!double.TryParse(Console.ReadLine(), out gpa) || !(gpa >= 0.0 & gpa <= 4.0)) goto r3;
Console.WriteLine("Your Information:\nUsername:{0}", login);
Console.WriteLine("Id:{0}", studentId);
Console.WriteLine("Name:{0} {1}", lastName, firstName);
Console.WriteLine("GPA:{0}", gpa);
Console.WriteLine("Grade:{0}", grade);
}
catch
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment