Задача 4. Ергенско парти
Здравейте, заяде ми 4-та задача от Подготовка за изпит C# - Основи на програмирането. Judge ми дава 70/100 - първите 3 теста кодът нещо поднася, не мога да открия къде е грешката:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bachelor_Party
{
class Program
{
static void Main(string[] args)
{
int singerPay = int.Parse(Console.ReadLine());
int peopleInThisGroup = 0;
int guests = 0;
int cover = 0;
int totalIncome = 0;
string command = string.Empty;
while (command != "The restaurant is full")
{
command = Console.ReadLine();
if (command != "The restaurant is full")
{
peopleInThisGroup = int.Parse(command);
guests += peopleInThisGroup;
if (peopleInThisGroup < 5)
cover = 100;
else
cover = 70;
totalIncome += peopleInThisGroup * cover;
}
else break;
}
int difference = totalIncome - singerPay;
if (difference > 0) Console.WriteLine($"You have {guests} guests and {difference} leva left.");
else Console.WriteLine($"You have {guests} guests and {totalIncome} leva income, but no singer.");
}
}
}
Ако някой може да помогне, ще съм му наистина благодарна.
Да, разбрах защо ми дава грешките - за да си позволи изпълнител, приходите на организатора трябва да са сума не само по-голяма от хонорара на изпълнителя, но може и да е равна на този хонорар. В моя код беше заложено само сумата да е по-голяма. Сега сложих >= и се оправи. Благодаря за отговора!
Здравейте, дава ми грешка при парсването от стринг към инт , може ли помощ
import java.util.Scanner; public class MensParty { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int sumForGuest = Integer.parseInt(scan.nextLine()); String input = scan.nextLine(); int allPeopleCnt = 0; double sumForAllPeople = 0; while (!input.equals("The restaurant is full.")) { int peopleCnt = Integer.parseInt(input); allPeopleCnt += peopleCnt; double income = 0; if (peopleCnt >= 5) { income = peopleCnt * 70; } else { income = peopleCnt * 100; } sumForAllPeople = sumForAllPeople + income; input = scan.nextLine(); } double diff = Math.abs(sumForGuest - sumForAllPeople); if (sumForAllPeople < sumForGuest){ System.out.printf("You have %d guests and %.0f leva income, but no singer.", allPeopleCnt, sumForAllPeople); } else { System.out.printf("You have %d guests and %.0f leva left.", allPeopleCnt, diff); } } }