js
js
CC#
Created by js on 5/5/2024 in #help
char.IsLetterOrDigit
does a whitespace count as letter or digit
17 replies
CC#
Created by js on 5/5/2024 in #help
directory.getfiles help
No description
17 replies
CC#
Created by js on 5/4/2024 in #help
✅ wont let me call my method
No description
17 replies
CC#
Created by js on 5/4/2024 in #help
foreach loop index error
foreach (string toppings in toppingsArray)
{
if (count <= toppingsArray.Length)
{
string topping = toppingsArray[count];
_names.Add(topping);
string price = toppingsArray[count + 1];
_prices.Add(price);
count = count + 2;
}
else if (count > toppingsArray.Length)
{
break;
}
}
foreach (string toppings in toppingsArray)
{
if (count <= toppingsArray.Length)
{
string topping = toppingsArray[count];
_names.Add(topping);
string price = toppingsArray[count + 1];
_prices.Add(price);
count = count + 2;
}
else if (count > toppingsArray.Length)
{
break;
}
}
10 replies
CC#
Created by js on 5/2/2024 in #help
invalid index error which i dont understand
No description
14 replies
CC#
Created by js on 5/1/2024 in #help
object reference not set to an instance of object error
No description
8 replies
CC#
Created by js on 5/1/2024 in #help
way to check if a string contains only alphabet
I need a line of code to check if a string contains only alphabet characters or whitespaces, what is the best way to do so
5 replies
CC#
Created by js on 4/30/2024 in #help
manipulating string
No description
42 replies
CC#
Created by js on 4/26/2024 in #help
✅ checking console input for certain letters
No description
8 replies
CC#
Created by js on 4/24/2024 in #help
how do i check if a string contains only words and space
ive got an if statement that needs to check if a string contains only letters or spaces, online i can only find how to check for only letters which then flags the spaces as not letters
19 replies
CC#
Created by js on 4/22/2024 in #help
✅ cant assign a value to a variable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using JustNom.Menu;
using JustNom.OrdersFolder;

namespace JustNom.Menu
{
internal abstract class FoodMenu
{
public static int selectedNum;

public static int numberOfLines;
public abstract string TakeawayName();
public abstract List<string> Toppings();
public abstract List<string> Garnishes();
public abstract List<string> LoadedBurgers();
public abstract List<string> LoadedPizzas();
public static void LoadFoodMenu()
{
Console.WriteLine("");
Console.WriteLine("JustNom Order Manager");
Console.WriteLine("");
Console.WriteLine("Please select a menu to load.");
Console.WriteLine("");

string[] filePaths = Directory.GetFiles(@"C:\Users\Joe\Documents\Uni\Programming Portfolio\JustNom\JustNom\TestData", "*.nom");

int count1 = 1;

foreach (string file in filePaths)
{
Console.WriteLine($"{count1}. {Path.GetFileName(file)}");
count1 = count1 + 1;
}

selectedNum = ConsoleHelpers.GetIntegerInRange(1, count1, "Please select a valid menu");

string[] selectedFile = File.ReadLines(filePaths[selectedNum - 1]).ToArray();

StreamReader reader = new StreamReader(filePaths[selectedNum - 1]);

numberOfLines = 0;
while (!reader.EndOfStream)
{
reader.ReadLine();
numberOfLines++;
}

reader.BaseStream.Seek(0, SeekOrigin.Begin);

TakeawayName = selectedFile[0];

Console.WriteLine($"{selectedFile[2]}");
}

}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using JustNom.Menu;
using JustNom.OrdersFolder;

namespace JustNom.Menu
{
internal abstract class FoodMenu
{
public static int selectedNum;

public static int numberOfLines;
public abstract string TakeawayName();
public abstract List<string> Toppings();
public abstract List<string> Garnishes();
public abstract List<string> LoadedBurgers();
public abstract List<string> LoadedPizzas();
public static void LoadFoodMenu()
{
Console.WriteLine("");
Console.WriteLine("JustNom Order Manager");
Console.WriteLine("");
Console.WriteLine("Please select a menu to load.");
Console.WriteLine("");

string[] filePaths = Directory.GetFiles(@"C:\Users\Joe\Documents\Uni\Programming Portfolio\JustNom\JustNom\TestData", "*.nom");

int count1 = 1;

foreach (string file in filePaths)
{
Console.WriteLine($"{count1}. {Path.GetFileName(file)}");
count1 = count1 + 1;
}

selectedNum = ConsoleHelpers.GetIntegerInRange(1, count1, "Please select a valid menu");

string[] selectedFile = File.ReadLines(filePaths[selectedNum - 1]).ToArray();

StreamReader reader = new StreamReader(filePaths[selectedNum - 1]);

numberOfLines = 0;
while (!reader.EndOfStream)
{
reader.ReadLine();
numberOfLines++;
}

reader.BaseStream.Seek(0, SeekOrigin.Begin);

TakeawayName = selectedFile[0];

Console.WriteLine($"{selectedFile[2]}");
}

}
}
18 replies
CC#
Created by js on 3/20/2024 in #help
need help with a console menu
No description
32 replies
CC#
Created by js on 2/23/2024 in #help
struggling with objects and methods
No description
3 replies
CC#
Created by js on 2/10/2024 in #help
extracting data from a text file into an array
im given multiple text files containing student marks and info etc and I need to access these files and extract each type of data such as exam marks student name etc into accessible arrays so I can do calculations on this. So far I have only managed to create a menu to select a file but I dont know how to extract the information from the text files
8 replies
CC#
Created by js on 2/6/2024 in #help
problem with console writeline
No description
9 replies
CC#
Created by js on 2/4/2024 in #help
function not running
int count = 1;
Console.WriteLine("Oyster Eating Competition\nHow many competitors are there?");
int numCompetitors = int.Parse(Console.ReadLine());
string[] names = new string[numCompetitors];
int[] oystersEaten = new int[numCompetitors];

for (int i = 0; i < numCompetitors; i++)
{
Console.WriteLine($"What is competitor number {count}'s name?");
names[i] = Console.ReadLine();
Console.WriteLine($"How many oysters did {names[i]} eat?");
oystersEaten[i] = int.Parse(Console.ReadLine());
count = count + 1;
}
static void bubbleSort(int[] oystersEaten)
{
int temp;

for (int i = 0;i < oystersEaten.Length - 1; i++)
{
for(int j = 0; j < oystersEaten.Length - (1 + i); j++)
{
if (oystersEaten[j] > oystersEaten[j + 1])
{
temp = oystersEaten[j + 1];
oystersEaten[j +1] = oystersEaten[j];
oystersEaten[j] = temp;
}
}
}
}
p.bubbleSort();
Console.WriteLine(string.Join(", ", oystersEaten));
int count = 1;
Console.WriteLine("Oyster Eating Competition\nHow many competitors are there?");
int numCompetitors = int.Parse(Console.ReadLine());
string[] names = new string[numCompetitors];
int[] oystersEaten = new int[numCompetitors];

for (int i = 0; i < numCompetitors; i++)
{
Console.WriteLine($"What is competitor number {count}'s name?");
names[i] = Console.ReadLine();
Console.WriteLine($"How many oysters did {names[i]} eat?");
oystersEaten[i] = int.Parse(Console.ReadLine());
count = count + 1;
}
static void bubbleSort(int[] oystersEaten)
{
int temp;

for (int i = 0;i < oystersEaten.Length - 1; i++)
{
for(int j = 0; j < oystersEaten.Length - (1 + i); j++)
{
if (oystersEaten[j] > oystersEaten[j + 1])
{
temp = oystersEaten[j + 1];
oystersEaten[j +1] = oystersEaten[j];
oystersEaten[j] = temp;
}
}
}
}
p.bubbleSort();
Console.WriteLine(string.Join(", ", oystersEaten));
it runs fine up until p.bubbleSort i think, im not sure how to call my function properly im just trying to use the sort to sort the array
36 replies
CC#
Created by js on 2/4/2024 in #help
program closing early
No description
64 replies
CC#
Created by js on 11/13/2023 in #help
max function in arrays
No description
17 replies