clone99
New member
- Joined
- Oct 17, 2022
- Messages
- 3
- Programming Experience
- 1-3
have makes this code and i want to writet the foreachlopp to to a textile. have try witch streamwriter but it not working . it only print out for one salerman,
can add that I am a beginner at programming
can add that I am a beginner at programming
C#:
using System.IO;
using System.Text;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
namespace Task2
{
internal class salesman // class for the salesman
{
public string name;
public string person;
public string location;
public int count;
public salesman(string name, string person, string location, int number) // calls the variables
{
this.name = name; // this. = reference to the class
this.person = person;
this.location = location;
this.number = number;
}
}
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine(" number of sales layers to be registered");
int snus = int.Parse(Console.ReadLine() ?? "0"); // enter how many sellers are to be registered
List<salesman> salesman = new List<salesman>(); // list for the class
for (int j = 0; j < snus; j++)
{
Console.WriteLine();
Console.WriteLine(" your name ");
var fornman = Console.ReadLine() ?? "0";
Console.WriteLine(" social security number ");
var number = Console.ReadLine() ?? "0";
Console.WriteLine(" enter palts/district ");
var dist = Console.ReadLine() ?? "0";
Console.WriteLine(" enter number ");
var items = int.Parse(Console.ReadLine() ?? "0");
Console.WriteLine();
var sa = new salesman(firstman, number, dist, items);
sälajre.Add(sa); //calls the method
}
var level1 = selajre.Where(n => n.number < 50); // level1
method seller(1, level1); // calls the method
var level2 = selajre.Where(n => n.count >= 50 && n.count < 100); // level2
method seller(2, level2);
var level3 = selajre.Where(n => n.count >= 100 && n.count < 200);// level3
method seller(3, level3);
var level4 = selajre.Where(n => n.number > 200); // level4
method seller(4, level4);
Console.ReadLine();
}
static async void method salesman(int level, IEnumerable<salesman> salesmen) // method salesman
{
if (!salesmen.Any())
{
return;
}
Console.WriteLine("-------------------");
foreach (var rape in salesmen.OrderBy(n => n.number)) // foreach is used to repeat the narrowing
{
Console.WriteLine("Name: " + rape.name); // displays seller name
Console.WriteLine("Personal ID: " + rape.person); //
Console.WriteLine("District/Location: " + rape.location); // display location
Console.WriteLine("Number sold " + rape.number); // shows how many items sold
Console.WriteLine("Seller has reached level " + level); // determines what level the seller has reached
Console.WriteLine("-----------------------------");
Console.WriteLine("-----------------------------");
}
string filename = "test.txt";
if (File.Exists(filename))
File.Delete(filename);
StreamWriter sw = new StreamWriter(filename);
sw.Write("Name: \n " + rape.name);
sw.Write("Personal identification number: \n " + rape.person);
sw.Write("District/Location: \n " + rape.location);
sw.Write("Number sold \n " + rape.number);
sw.Write("Seller has reached level \n " + level);
sw.Close();
}
Console.WriteLine(salesmen.Count() + " salesman has reached level " + level); // prints the level at which most sellers have sold
Last edited by a moderator: