Задача 6. Baking competition
Стигнах до някъде с последната задача, забих до съхраняването на променливите за съответният уяастник и количеството , само насоки ми трябва ако някой има такива. :
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
int people;
cin >> people;
string person;
int currentAmountCookies = 0 ;
int currentAmountCakes = 0 ;
int currentAmountWaffles = 0 ;
for(int i = 1 ; i <= people ; i++){
cin >> person;
string type;
cin >>type;
while(type != "Stop"){
int amount =0;
cin >> amount;
if(type == "cakes" ){
currentAmountCakes = amount;
cin >> type;
}else if(type == "cookies" ){
currentAmountCookies= amount;
cin >> type;
}else if(type == "waffles" ){
currentAmountWaffles = amount;
cin >> type;
}
}
}
cout << currentPerson << " baked " << currentAmountCookies << " cookies " << currentAmountCakes << " cakes " << currentAmountWaffles << " waffles " << endl;
cout << "All bakery sold: " <<currentAmountCookies + currentAmountCakes + currentAmountWaffles << endl;
cout << "Total sum for charity: ";
return 0;
}
Здравей ето едно решение на C# дано ти помогне да се ориентираш: Не можах да разбера къде си пресмятал/а. Затова виж аз как съм ги запазила.
using System;
namespace Baking_Competition
{
class Program
{
static void Main(string[] args)
{
int countPeople = int.Parse(Console.ReadLine());
double allsweets = 0;
double allSum = 0;
for (int i = 0; i < countPeople; i++)
{
string name = Console.ReadLine();
string typeCake = Console.ReadLine();
double price = 0;
double countCookis = 0;
double countCakes = 0;
double countWaffles = 0;
while (typeCake != "Stop baking!")
{
int countSladki = int.Parse(Console.ReadLine());
if (typeCake == "cookies")
{
price = 1.50;
price = countSladki * price;
countCookis += countSladki;
}
else if (typeCake == "cakes")
{
price = 7.80;
price = countSladki * price;
countCakes += countSladki;
}
else if (typeCake == "waffles")
{
price = 2.30;
price = countSladki * price;
countWaffles += countSladki;
}
allsweets += countSladki;
allSum += price;
typeCake = Console.ReadLine();
}
Console.WriteLine($"{name} baked {countCookis} cookies, {countCakes} cakes and {countWaffles} waffles.");
}
Console.WriteLine($"All bakery sold: {allsweets}");
Console.WriteLine($"Total sum for charity: {allSum:f2} lv.");
}
}
}
Успех !