Guest User

Reddit project 1e

a guest
Feb 10th, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. /*
  2.  * DESCRIPTION:
  3.     create a program that will ask the users name, age, and reddit username. have it tell them the information back, in the format:
  4.     your name is (blank), you are (blank) years old, and your username is (blank)
  5.     for extra credit, have the program log this information in a file to be accessed later.
  6. */
  7.  
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12.  
  13. namespace First_Easy
  14. {
  15.     class Program
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             string name;
  20.             int age;
  21.             string reddit;
  22.  
  23.             //get name from user
  24.             Console.Write("Enter your name: ");
  25.             name = Console.ReadLine();
  26.             Console.WriteLine();
  27.  
  28.             //get age from user
  29.             string testAge;
  30.             do
  31.             {
  32.                 Console.Write("Enter your age: ");
  33.                 testAge = Console.ReadLine();
  34.                 Console.WriteLine();
  35.             } while (!int.TryParse(testAge, out age));
  36.  
  37.             //get reddit name from user
  38.             Console.Write("Enter your reddit username: ");
  39.             reddit = Console.ReadLine();
  40.             Console.WriteLine(Environment.NewLine);
  41.  
  42.             //Print the info on screen
  43.             Console.WriteLine("your name is {0}, you are {1} years old, and your username is {2}", name, age, reddit);
  44.             Console.ReadKey();
  45.  
  46.             //ninja add to file to hack this user later
  47.             string secretLogFile = Environment.GetEnvironmentVariable("appdata");
  48.             secretLogFile = System.IO.Path.Combine(secretLogFile, "redditProgramming");
  49.             if (!System.IO.Directory.Exists(secretLogFile)) System.IO.Directory.CreateDirectory(secretLogFile);
  50.             secretLogFile = System.IO.Path.Combine(secretLogFile, "first_easy.csv");
  51.             string logInfo = string.Format("\"{1}\";{2};\"{3}\"{0}", Environment.NewLine, name, age, reddit);
  52.             System.IO.File.AppendAllText(secretLogFile, logInfo);
  53.         }
  54.     }
  55. }
Add Comment
Please, Sign In to add comment