0
#include<cs50.h>
#include<stdio.h>
#include<math.h>
int main()
{
float f=0;
long int a=0,c=0;
printf("Enter the float value:");
do
{
    f = get_float();

}while(f <= 0);

a = (int) round(f*100);
{
   while(a>=25)
   {
       c++;
       a=a-25;
   }
    while(a>=10)
   {
       c++;
       a=a-10;
   }
    while(a>=5)
   {
       c++;
       a=a-5;
   }
    while(a>=1)
   {
       c++;
       a=a-1;
    }

  printf("%ld\n",c);
  }
return 0;
}

I am getting all correct expect negative integer it is not accepting a negative integer which I need to valid that is also true by output. The negative integer should be less than zero right as per rules and I have correctly declared. I am not sure where it went wrong. Please assist

0

If you want to debug your code, it is good to look at the errors you are getting. Check50 prints out this error:

\ expected output, not a prompt for input

What does this mean? Instead of asking the user to provide a positive number, you simply prompt for input. Check50 was expecting you to ask the user for a number rather than immediately prompting for input. To fix this, simply add a printf before your f = get_float(). When I did this, your code passed check50. Of course, you can make the printf say whatever you want, but it's good to simply ask for another number.

If this answers your question, please hit the green checkmark. If you have issues, comment below. :-)

| improve this answer | |
  • Thank you so much.. this answers my questions.. so how can i tackle this kind of problem in future..Thanks for correcting me :) – Arivezhil Namasivayam Apr 4 '17 at 2:33
  • I'm glad it helped you! For future problems, looking at what the terminal outputs can tell you a lot about what the problem is. The errors can even tell you where the problem occurs. You can also put printfs all over your code and then run your program to see the values of different variables. You could also use debug50 or other debugging methods to go line-by-line through your code to find the error. – SuperNovaCoder Apr 4 '17 at 11:23
0

If the user fails to provide a non-negative value, your program should re-prompt the user for a valid amount again and again until the user complies.

First, non-negative means your check should be while (f < 0), not while (f <= 0). Second, your printf should go into the loop, as the tester probably assumes that you receive some additional output if entered value was negative.

| improve this answer | |
  • Can you please explain more clearly.. Still I didnt get the answer.. I have changed the while condition. Still it is giving error – Arivezhil Namasivayam Apr 3 '17 at 16:01
  • @SuperNovaCoder Citing specs: "If the user fails to provide a non-negative value, ..." (so 0 is a valid input value) – Blauelf Apr 3 '17 at 18:19
  • @ArivezhilNamasivayam Before you re-prompt the user, the tester expects some output from your programme. One way to deal with that is by including the printf statement that's directly before the do..while loop into the loop, having both printf and get_float in the loop. – Blauelf Apr 3 '17 at 18:22
  • @Blauelf, you are correct, my apologies. – SuperNovaCoder Apr 3 '17 at 19:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .