how to create this in a loop

vectrapower

New member
Joined
May 2, 2021
Messages
2
Programming Experience
Beginner
i am making a program that i can choose multiply times options 1 till 4 till i hit 5 that i finished my order . it is made in a windows form app.
C#:
private static int lijstaccessoires()
        {
            Console.WriteLine("kies uw accesoires ");
            Console.WriteLine("Regendak type 1 ");
            Console.WriteLine("Babystoel type 2 ");
            Console.WriteLine("Smartphonehouder type 3 ");
            Console.WriteLine("Helm type 4 ");
            string[] acc = { "Regendak", "Babystoel", "Smartphonehouder", "Helm " };
            int prijsaccessoires = 0;
            int keuze;
            int.TryParse(Console.ReadLine(), out keuze);
      
            {
               if (keuze == 1)
            prijsaccessoires = 10;
                if(keuze == 2)
            prijsaccessoires = 20;
               if (keuze == 3)
            prijsaccessoires = 15;
              if  (keuze == 4)
            prijsaccessoires = 15;
            }
       
            return prijsaccessoires;
 
Last edited by a moderator:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,994
Location
Chesapeake, VA
Programming Experience
10+
In the future, please post your code in code tags. It preserves the line indentation and therefore makes reading the code easier.

If your program is in WinForms, then you don't do the same type menu approach that you are presenting in your code above. That code above is the console program approach. In a WinForms program, you could either have 4 menu items on a menu, or 4 buttons. You handle each of the menu selection or button clicks as appropriate. A WinForms program should close when you click on a X button on the to right corner of the window chrome, or you could also have an option to close the program via another menu option or button.
 

vectrapower

New member
Joined
May 2, 2021
Messages
2
Programming Experience
Beginner
my bad i am new to this forum . what i mean to say is i made it in a console program . the question is how to put the code that lijstaccessoires can run more option like 2 times type 2 till i hit keuze 5 to end


my program:
using System;

namespace fietsbak
{
    class Program
    {
        

        static void Main(string[] args)
        {
            Console.WriteLine("Welkom bij de applicatie van: Van der Binckes Bakfietsen. ");
            Console.WriteLine(" ");
            int keuze = keuzefiets();
            int aantaldagen = kiesaantaldagen();
            int accessoires = lijstaccessoires();
            int prijs = prijstotaal(keuze , aantaldagen , accessoires);
            Console.WriteLine(prijs);         
        }

        private static int prijstotaal(int a, int b ,int c )
        {
            Console.WriteLine("De totale kosten van uw bakfiets bedraagd:");
            int d = a + b + c ;
            return d;
        }

        private static int lijstaccessoires()
        {
            Console.WriteLine("kies uw accesoires ");
            Console.WriteLine("Regendak type 1 ");
            Console.WriteLine("Babystoel type 2 ");
            Console.WriteLine("Smartphonehouder type 3 ");
            Console.WriteLine("Helm type 4 ");
            string[] acc = { "Regendak", "Babystoel", "Smartphonehouder", "Helm " };
            int prijsaccessoires = 0;
            int keuze;
            int.TryParse(Console.ReadLine(), out keuze);
            {
               if (keuze == 1)
            prijsaccessoires = 10;
                if(keuze == 2)
            prijsaccessoires = 20;
               if (keuze == 3)
            prijsaccessoires = 15;
              if  (keuze == 4)
            prijsaccessoires = 15;
            }
        
            return prijsaccessoires;
        }
        
        private static int keuzefiets()
        {
            
            Console.WriteLine("Type bakfiets:");
            Console.WriteLine("Voor Standaard kies 1");
            Console.WriteLine("Voor Elektrisch kies 2");
            int prijsfiets = 0;
            int keuze;
            int.TryParse(Console.ReadLine(), out keuze);
            if (keuze == 1)
            prijsfiets = 10;
            if (keuze == 2)
            prijsfiets = 20;
            return prijsfiets;
        }

        private static int kiesaantaldagen()
        {
            Console.WriteLine("dagen van de fiets huren ");
            Console.WriteLine("min 1 dag maximaal 7 dagen");
            Console.WriteLine("type aantal dagen in");
            int aantaldagenprijs = 0;
            int keuze;
            int.TryParse(Console.ReadLine(), out keuze);
            if (keuze == 1)
            aantaldagenprijs = 30;
            if (keuze == 2)
            aantaldagenprijs = 25;
            if (keuze == 3)
            aantaldagenprijs = 20;
            if (keuze == 4)
            aantaldagenprijs = 15;
            if (keuze == 5)
            aantaldagenprijs = 10;
            if (keuze == 6)
            aantaldagenprijs = 5;
            if (keuze == 7)
            aantaldagenprijs = 2;
            return aantaldagenprijs;
            
        }
    }
}
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,994
Location
Chesapeake, VA
Programming Experience
10+
Moving this thread out of the WinForms subforum then if this is meant to be a console program...
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
2,994
Location
Chesapeake, VA
Programming Experience
10+
Since you need to loop until the user selects that option, that you implied that you need to use some kind of loop. You should have learned about looping flow control by now since you've already done branching flow control, as well as method calls. What have you covered in your classes and lectures seems like the appropriate looping flow control for your needs?
 
Top Bottom