should return class type data but I get error msg

cfrank2000

Well-known member
Joined
Mar 6, 2021
Messages
71
Programming Experience
Beginner
Hi
I am doing my c# homework, szezonar (sezon price) function should return class type data but I get error
Severity Code Description Project File Line Suppression State
Error CS0161 'Program.szezonar(int, int)': not all code paths return a value szalloda1 C:\Users\Dell\source\repos\szalloda1\szalloda1\Program.cs 32 Active
please help me thank you.

hotelorder1:
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace szalloda1
{
    public class pitypang00
    {
        public int foglaloszam = 0;
        public int szobaszam = 0;
        public int erkezesinapsorszama = 0;
        public int tavozasinapsorszam = 0;
        public int vendegszam = 0;
        public int kernekreggelit = 0;
        public string vendegazonosito = " ";
        public int tartozkodashosz = 0;
        public int teljesar = 0;
    }
    class return1
    {
        public int koz0 = 0;
        public int ar = 0;
        public string st0 = " ";
    }
    class Program
    {
        //public int szezonar(int kezd, int veg, ref int koz0, ref string st0)
        //public int szezonar(int kezd, int veg, out int koz0, out string st0)
        //static return1 szezonar(int kezd0, int veg0, int koz0, int ar, string st0)
        static return1 szezonar(int kezd0, int veg0)
        {
            int tavasz = 9000;
            int nyar = 10000;
            int osz = 8000;
            int koz = 0;

            return1 record0 = new return1();

            if (kezd0 > 1 && kezd0 < 120 && veg0 > 1 && veg0 < 120)
            {
                record0.st0 = " Tavaszi szezon ";
                record0.ar = tavasz;
                record0.koz0 = koz;
                return record0;
            }
            if (kezd0 > 121 && kezd0 < 243 && veg0 > 121 && veg0 < 243)
            {
                record0.st0 = " Nyari szezon ";
                record0.ar =  nyar;
                record0.koz0 = koz;
                return record0;
            }
            if (kezd0 > 244 && kezd0 < 365 && veg0 > 244 && veg0 < 365)
            {
                record0.st0 = " Oszi szezon ";
                record0.ar = osz;
                record0.koz0 = koz;
                return record0;
            }
            if (kezd0 > 1 && kezd0 < 120 && veg0 > 121 && veg0 < 243)
            {
                record0.st0 = " Tavaszi szezon/Nari szezon ";
                record0.ar = veg0-120;
                record0.koz0 = 120 - kezd0;
                return record0;
            }
            if (kezd0 > 121 && kezd0 < 243 && veg0> 244 && veg0 < 365)
            {
                record0.st0 = " Nari szezon/Oszi szezon ";
                record0.ar = veg0-243;
                record0.koz0 = 243 - kezd0;
                return record0;
            }
            if (kezd0 > 244 && kezd0 < 365 && veg0 > 1 && veg0 < 120)
            {
                record0.st0 = " Tavaszi szezon/Nari szezon ";
                record0.ar = 120-veg0;
                record0.koz0 = 365 - kezd0;
                return record0;
            }

        }

        static void Main(string[] args)
        {
            int i = 0;
            int i2 = 0;
            int kod0 = 0;
            int utolso = 0;
            int csere = 0;
            int max = 0;
            int indexmax = 0;

            int erkez = 0;
            int tavoz = 0;
            //int tartozkodas = 0;
            //int koz = 0;
            // string msg = " ";


            string olvas = @"c:\Users\Public\textfiles\pitypang.txt";
            List<pitypang00> adatok = new List<pitypang00>();

            try
            {
                
                // Open the text file using a stream reader.
                using (var sr = new StreamReader(olvas, Encoding.Default))
                {
                    // Read the stream as a string, and write the string to the console.
                    //Console.WriteLine(sr.ReadToEnd());
                    while (!sr.EndOfStream)
                    {

                        string sor = sr.ReadLine();
                        string[] record = sor.Split(' ');

                        adatok.Add(new pitypang00());
                        if (i == 0) { kod0 = Convert.ToInt32(record[0]); }
                        else
                        {   
                            erkez = Convert.ToInt32(record[2]);
                            tavoz = Convert.ToInt32(record[3]);
                            return1 szezon = szezonar(erkez,tavoz);
                            adatok[i].foglaloszam = Convert.ToInt32(record[0]);
                            adatok[i].szobaszam = Convert.ToInt32(record[1]);
                            adatok[i].erkezesinapsorszama = erkez;
                            adatok[i].tavozasinapsorszam = tavoz;
                            adatok[i].vendegszam = Convert.ToInt32(record[4]);
                            adatok[i].kernekreggelit = Convert.ToInt32(record[5]);
                            adatok[i].vendegazonosito = record[6];
                            adatok[i].tartozkodashosz = Convert.ToInt32(record[3])- Convert.ToInt32(record[2]);
                            adatok[i].teljesar = szezon.ar;

                            Console.WriteLine(" i " + i +" " + adatok[i].foglaloszam + " " + record[6] + " " + adatok[i].szobaszam + " " + adatok[i].erkezesinapsorszama);

                        }
                        i++;
                        if (i == 1) { Console.WriteLine(" i " + i + " " + kod0); }
                        
                    }
                    utolso=i;
                    int[] novekvo = new int[utolso];
                    Console.WriteLine(" utolso " + utolso);
                    sr.Close();

                    for (i2 = 1; i2 < utolso; i2++)
                    {
                        Console.WriteLine("  Vendeg ID  " + adatok[i2].vendegazonosito);
                        Console.WriteLine(
                                "  Foglaloszam  " + adatok[i2].foglaloszam +
                                "  Szobaszam   " + adatok[i2].szobaszam +
                                "  Erkezesinap szama  " + adatok[i2].erkezesinapsorszama +
                                "  Tavozasinap szama  " + adatok[i2].tavozasinapsorszam +
                                "  Vendegszam   " + adatok[i2].vendegszam +
                                "  Kernek reggelit   " + adatok[i2].kernekreggelit +
                                "  Tartozkodas hosz " + adatok[i2].tartozkodashosz);

                        novekvo[i2] = i2;
                        
                    }
                    for (i = 1; i < utolso; i++)
                        for (i2 = 2; i2 < utolso; i2++)
                        {
                        
                        if (adatok[novekvo[i2]].tartozkodashosz < adatok[novekvo[i2-1]].tartozkodashosz)
                        {
                            csere = novekvo[i2];
                            //csere2 = novekvo[i2-1];
                            novekvo[i2] = novekvo[i2 - 1];
                            novekvo[i2 - 1] = csere;
                                
                        }
                        
                    }
                    max = adatok[novekvo[utolso - 1]].tartozkodashosz;
                    indexmax = novekvo[utolso - 1];
                    Console.WriteLine("index max " + indexmax+"max " +max);
                    /*
                    for (i = 1; i < utolso; i++)
                    {
                        Console.WriteLine(
                        i+"  Tartozkodas hosz "+ novekvo[i] + " " + adatok[novekvo[i]].tartozkodashosz);
                    }*/
                    for (i = 1; i < indexmax + 1; i++)
                    {
                        if (i == indexmax)
                            {
                            Console.WriteLine(" "+ i +
                                "  Vendeg azonosito  " + adatok[i].vendegazonosito+
                                "  Erkezesinap szama  " + adatok[i].erkezesinapsorszama +
                                "  Leghosszabb tartozkodas  " + adatok[i].tartozkodashosz);
                            }
                    }
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
           // Console.WriteLine(" Test "+utolso+ adatok[i2].vendegazonosito);
        }
    }
}
 

Attachments

  • pitypang.txt
    31.8 KB · Views: 15
See record 688, find the values that is passed to your function. Find the condition that you think should match those values.
If it doesn't match fix your code.
If you think it should match, but code is still stepped over, then post the relevant values and the expression that you think should match it.
 
Back
Top Bottom