Задание Paint Cost. Help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Задание Paint Cost. Help

По заданию 1, 2 и 5 проверки выполнены. А вот 3 и 4 до сих пор не выходит сделать. Вот код: #include <iostream> using namespace std; int main() { int color, tax, money; cin >> color; if(color > 0) { color = color * 5 + 40; tax = (color * 10) / 100; money = tax + color; cout << money; } if(color == 0) cout << 44; else return 0; return 0; }

26th Jan 2020, 12:13 PM
Zjoos
Zjoos - avatar
10 Answers
+ 1
cout<<(int)ceil(money) ;
26th Jan 2020, 1:36 PM
Jayakrishna 🇮🇳
+ 2
Ex: ceil(4.7) will return 5.0 (int)ceil(4.7) will return 5 Output asked there is round up the result into nearest Integer. So without that casting int, then it will print 5.0
26th Jan 2020, 2:10 PM
Jayakrishna 🇮🇳
+ 1
But further your understanding, Iam saying it can done by without If - else. And further with only one variable... And you are Wel come Georgiy Voevodin
26th Jan 2020, 2:20 PM
Jayakrishna 🇮🇳
0
Cost is 40.00, paint cost is 5.00 so you have to deal with float or double type. And round up the result(use ceil function) then print. Стоимость 40,00, стоимость краски 5,00, поэтому вам придется иметь дело с плавающей или двойной тип. И округлите результат (используйте функцию ceil), затем напечатайте.. double color, tax, money; cout<<ceil(money) ;
26th Jan 2020, 12:51 PM
Jayakrishna 🇮🇳
0
Не выходит. Вот отрывок исправленного кода: cout << ceill(money); Теперь у меня не выполена проверка 5 и 3
26th Jan 2020, 1:04 PM
Zjoos
Zjoos - avatar
0
Paste your modified code here..
26th Jan 2020, 1:08 PM
Jayakrishna 🇮🇳
0
#include <iostream> #include <cmath> using namespace std; int main() { double color, tax, money; cin >> color; if(color > 0) { color = color * 5 + 40; tax = (color * 10) / 100; money = tax + color; cout << ceil(money); } if(color == 0) cout << 44; else return 0; return 0; }
26th Jan 2020, 1:26 PM
Zjoos
Zjoos - avatar
0
А int зачем? Там же и так целое число получается округленное?
26th Jan 2020, 2:04 PM
Zjoos
Zjoos - avatar
0
Thanks a lot!)
26th Jan 2020, 2:12 PM
Zjoos
Zjoos - avatar
0
Спасибо! Я в тот момент просто не понимал почему 3 и 5 не выполняется. Думал что дело в дополнительных условиях
26th Jan 2020, 2:48 PM
Zjoos
Zjoos - avatar