Don't worry anymore my bae's im gonna do it
I need to do this for school but writing pseudocode is boring so do it for me pl0x $5 paypal
and delete all the comments and useless crap
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace Assignment {
class Program {
const string PATH = @"D:\binaryfirecodes.txt";
static StreamReader sr = new StreamReader(PATH);
static int numDec = 0;
static string numBin = "";
static Boolean ask = true;
static char choice;
/*
* FUNCTION section
*/
static string Function_PathConvert (string numBin) { // The function
while ((numBin = sr.ReadLine()) != null) {
for (int i = 0; i <= numBin.Length - 1; i++) {
numDec += Convert.ToInt32(numBin[i].ToString()) * Convert.ToInt32(Math.Pow(2, numBin.Length - 1 - i));
}
Console.WriteLine(numDec);
numDec = 0;
}
return numDec.ToString();
}
static string Function_BinConvert (string numBin) { // The add function
for (int i = 0; i <= numBin.Length - 1; i++) { // Makes an int i and if i is <= the length of the binary number - 1 it will run this code then add 1 to the int i
numDec += Convert.ToInt32(numBin[i].ToString()) * Convert.ToInt32(Math.Pow(2, numBin.Length - 1 - i));
}//for
return numDec.ToString();
}
/*
* VOID section
*/
static void binConvert () {
Console.Clear();
while (ask) {
Regex r = new Regex(@"^[0-1]*$");
Console.Write("Enter a binary number and I will convert it to a decimal.\nBinary number: "); // Writes instructions
numBin = Console.ReadLine(); // Reads the line and sets numBin to whatever it reads.
if (!r.IsMatch(numBin)) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Invalid Number, binary numbers consist of only 1's and 0's.\n");
Console.ForegroundColor = ConsoleColor.Gray;
}
else {
Function_BinConvert(numBin);
Console.WriteLine("Decimal number: " + numDec + "\n"); // Writes the Decimal number.
}
numDec = 0;
numBin = "";
}//while
}
static void pathConvert () {
Console.Clear();
StreamReader sr = new StreamReader(PATH);
if (!File.Exists(PATH)) {
Console.WriteLine("File does not exist.");
}
else {
Function_PathConvert(numBin);
}
Console.ReadLine();
}
static void start () {
Console.Clear();
Console.WriteLine("Press 'A' to convert a binary number to a decimal number.\nPress 'B' to convert binary numbers in a file to decimal.");
try {
choice = Convert.ToChar(Console.ReadLine().ToLower());
} catch {
start();
}
switch (choice) {
case 'a':
binConvert();
break;
case 'b':
pathConvert();
break;
default:
start();
break;
}
}
static void Main (string[] args) {
try {
start();
} catch {
start();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace Assignment2 {
class Program {
static int i = 0;
static int ii = 0;
static string input = "";
static string[] classNames = new string[20];
const string PATH = @"J:\names.txt";
//static StreamReader sr = new StreamReader(PATH);
static Random r = new Random();
/*
* ********** FUNCTION Section **********
*/
static void addNames () {
StreamReader sr = new StreamReader(PATH);
while (i < classNames.Length) {
classNames[i] = sr.ReadLine();
i++;
}
}
static void writeNames () {
while (i >= classNames.Length && ii < classNames.Length) {
Console.WriteLine(classNames[ii]);
ii++;
}
}
static void writeFile () {
while (i < classNames.Length) {
Console.Write("Enter Name {0}: ", i + 1);
classNames[i] = Console.ReadLine();
i++;
}
File.WriteAllLines(PATH, classNames);
StreamReader sr = new StreamReader(PATH);
Console.Clear();
Console.WriteLine("Stored Names:\n");
while ((input = sr.ReadLine()) != null) {
Console.WriteLine(input);
}
}
static void randomNames () {
while (true) {
int a = r.Next(2);
if (a == 0) {
Console.Write("The winner of the tuckshop voucher is: " + classNames[5] + "\nCongratulations!\n\nPress Enter to find another winner.");
}
else {
Console.Write("The winner of the tuckshop voucher is: " + classNames[r.Next(classNames.Length)] + "\nCongratulations!\n\nPress Enter to find another winner.\n");
}
Console.ReadLine();
}
}
/*
* ********** MAIN Section **********
*/
static void Main (string[] args) {
while (true) {
if (!File.Exists(PATH)) {
writeFile();
}
else if (File.Exists(PATH)) {
Console.WriteLine("Students:\n");
addNames();
writeNames();
Console.WriteLine();
randomNames();
}
}
}
}
}