+ 2
Why this code is wrong for 3 and 5 test cases in PAINT COSTS.
#include <iostream> #include <cmath> using namespace std; int main() { int x; float pntcst,tax,c,p; cin>>x; p=x*5.00; c=p+40.00; tax=c/10; pntcst=c+tax; cout<<round(pntcst); return 0; }
8 Respuestas
0
Just replace
round( pntcst )
with
( int )ceil( pntcst )
and you should be good to go.
0
First of all, the task requires you to round the result up, but round() rounds either up or down, depending on the number. ceil() might be more fitting in this case.
Also, I remember some issues from the past where printing a float value didn't trigger the test case, although the result was correct, where casting the result to int before printing helped.
0
Shadow type the right programm
0
Thank you Shadow
0
Now i have other doubt.
#include <iostream>
using namespace std;
int main()
{
int n,i=1;
cin>>n;
if(n<10)
{
while(i<=n)
{
cout<<"Ra!";
i++;
}
}
if(n<1)
{
cout<<"shh";
}
if(n>10,n==10)
{
cout<<"High Five";
}
return 0;
}
Why this code is wrong for 3 and 4 test cases in cheer creater.
0
1. If n < 10, you execute the first two if-statements because both conditions are true.
2. If you want to chain conditions like in the third if-statement, you have to use logical operators, e.g. &&. The comma operator has a different meaning in C++.
Overall, you should restructure the whole control flow a bit:
if ( n < 1 ) { /* ssh */ }
else if ( n < 10 ) { /* Ra! */ }
else { /* High Five */ }
0
#include <iostream>
using namespace std;
int main()
{
int n,i=1;
cin>>n;
if(n<1)
cout<<"shh";
else if(n<10)
while(i<=n)
{
cout<<"Ra!";
i++;
}
else
cout<<"High Five";
return 0;
}
This code make wrong for 4th case. why?
0
I just re-read the task again and it states to print "Ra!" for ten or less yards, so you would have to change the condition from n < 10 to n <= 10 to reflect this.