0
Paint cost
Im trying to figure out to round to the nearest whole number #include <iostream> using namespace std; int canvas= 40; int paint=5; int colors; int beforetax ; int aftertax ; int main() { cin>> colors; beforetax = colors*paint+canvas; aftertax=beforetax*.1 + beforetax ; cout<< aftertax ; return 0; }
4 ответов
+ 2
There is a function for that. For normal rounding to the nearest integer you would used the round() function (clever name, eh?). However, for this Code Coach task it does not ask for normal rounding.
If you look closer at the task you may notice that they want the number always rounded up.
There is a function for that. To always round up, use the ceil() function. It promotes any fractional value upward to the next ceiling value, that is, the next higher integer.
+ 1
Angel Jimenez one minor adjustment is needed. Declare int up instead of double up.
+ 1
Thanks thought it was something minor
0
I tried it and it works for all the cases except #5 idk if i did it right
#include <iostream>
#include <cmath>
using namespace std;
int canvas= 40;
int paint=5;
int colors;
double beforetax ;
double aftertax ;
int main() {
cin>> colors;
beforetax = colors*paint+canvas;
aftertax=beforetax*.1 + beforetax ;
double up = ceil(aftertax);
cout<< up ;
return 0;
}