-2

ROBOT BARMAN

Robot-barman You have a robot-barman and his goal is to neatly arrange drinks on the shelves of the bar. He is very smart and takes as many drinks as are necessary to evenly distribute them on the shelves, but he still has problems with division. The program installed in the robot takes the number of drinks and the number of the shelves as input. Complete the program to evenly distribute the drinks on shelves: by dividing the number of drinks by the number of shelves and outputting the result. The program must also, handle those two possible problems: 1. the divider (the number of shelves) should never be zero 2. both inputs should be integers. For the first exception, the program should output "At least 1 shelf" and for the second, "Please insert an integer". Sample Input 6 two Sample Output Please insert an integer using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { try { int drinks = Convert.ToInt32(Console.ReadLine()); int shelves = Convert.ToInt32(Console.ReadLine()); //your code goes here } /* * 1. DivideByZeroException => "At least 1 shelf" * 2. FormatException => "Please insert an integer" */ catch () { } catch () { } } } }

3/10/2021 3:00:00 PM

Bonn Cabello

+7

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { try { int drinks = Convert.ToInt32(Console.ReadLine()); int shelves = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(drinks / shelves); } catch (DivideByZeroException e) { Console.WriteLine("At least 1 shelf"); } catch(Exception e) { Console.WriteLine("Please insert an integer"); } } } } this one is working!!

+3

+1

You should be able to do this as you learned Exception handling in lesson 70.1 right before. Repeat it if necessary and apply to this problem. Try it and make an attempt. If you have a specific problem, please describe it and also post your code. Only then we can help you

+1

thanks man!

0

help pls?

0

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { try { int drinks = Convert.ToInt32(Console.ReadLine()); int shelves = Convert.ToInt32(Console.ReadLine()); //your code goes here try { drinks / shelves; } catch (DivideByZeroException e) { Console.WriteLine("Error"); } finally { Console.WriteLine(result); } catch () { } catch () { } } } } this one

0

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { try { int drinks = Convert.ToInt32(Console.ReadLine()); int shelves = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(drinks / shelves); } catch (DivideByZeroException e) { Console.WriteLine("atleast 1 shelf"); } catch(Exception e) { Console.WriteLine("An error occurred"); } } } } this is the code that i tried but only worked for test case 1,4 and 5,, test case 2 and 3 is error, anyone help>?

0

Bonn Cabello check the expected output again. It has to be exact. You can copy it from the code comment they give you

0

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { try { int drinks = Convert.ToInt32(Console.ReadLine()); int shelves = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(drinks / shelves); } catch (DivideByZeroException e) { Console.WriteLine("At least 1 shelf"); } catch (Exception e) { Console.WriteLine("Please insert an integer"); } } } } working

0

namespace SoloLearn { class Program { static void Main(string[] args) { try { int drinks = Convert.ToInt32(Console.ReadLine()); int shelves = Convert.ToInt32(Console.ReadLine()); //your code goes here Console.WriteLine(drinks/shelves); } /* * 1. DivideByZeroException => "At least 1 shelf" * 2. FormatException => "Please insert an integer" */ catch (DivideByZeroException e) { Console.WriteLine("At least 1 shelf"); } catch (FormatException e) { Console.WriteLine("Please insert an integer"); } } } } As per the question we need to use the proper exception. i.e "FormatException "

0

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { try { int drinks = Convert.ToInt32(Console.ReadLine()); int shelves = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(drinks / shelves); } catch (DivideByZeroException e) { Console.WriteLine("At least 1 shelf"); } catch(Exception e) { Console.WriteLine("Please insert an integer"); } } } }

0

static void Main(string[] args) { try { int drinks = Convert.ToInt32(Console.ReadLine()); int shelves = Convert.ToInt32(Console.ReadLine()); //your code goes here Console.WriteLine(drinks / shelves); } /* * 1. DivideByZeroException => "At least 1 shelf" * 2. FormatException => "Please insert an integer" */ catch (DivideByZeroException e) { Console.WriteLine("At least 1 shelf"); } catch (FormatException e) { Console.WriteLine("Please insert an integer"); } }