hello!

Im making a program that makes the numbers you input be divided into diffrent denominations which is in peso.

example:
i input: 1500

so the output will be

BILL QTY
1000 1
500 1


my problem is, after it displays the output, I want the program to ask you "do you want to input another amount?" and if you input Y, it will go back to the start. and if you input no, it will exit.

EDIT:I would also want to add the function that if you will enter a letter instead of a number, it will say invalid input.
thanks!


I attached my C file.. pls take a look at my program

Recommended Answers

All 4 Replies

At the risk of confusing you, I'll offer a more robust solution than you'd normally be given. Since it's more complex, I'll happily explain anything you don't understand:

#include <stdio.h>
#include <string.h>

int continue_working ( const char *msg, const char *true_case )
{
  char buffer[BUFSIZ];

  /*
    Don't do printf(msg);
    It invites malicious input strings
  */
  printf ( "%s", msg );

  /* Force a flush because '\n' wasn't printed */
  fflush ( stdout );

  /*
    Using line input to avoid both a dirty stream
    and ugly/dubious stdin flushing techniques
  */
  if ( fgets ( buffer, sizeof buffer, stdin ) == NULL ) {
    /*
      You can get clever here if you want, I
      just kept it simple at fgets fails means stop working
    */
    return 0;
  }

  /* Remove '\n' from the buffer if it's there */
  buffer[strcspn ( buffer, "\n" )] = '\0';

  return strcmp ( buffer, true_case ) == 0;
}

int main ( void )
{
  /*
    Loop forever
    while ( 1 ) may not give a clean compile
  */
  for ( ; ; ) {
    /* Replace this line with your program's real work */
    printf ( "Doing work!\nDone.\n" );
    
    if ( !continue_working ( "Keep working? (y/n): ", "y" ) )
      break;
  }

  return 0;
}

uhhm.. if i use this, its clear that i asked someone to helped me..

is there no any other solution using the basic codes i used in my source code?

like if, while, for, printf, etc..

actually our prof is still teaching us the basics.. but i cant figure out a way to put my program back to the main menu with the use of these basic codes

uhhm.. if i use this, its clear that i asked someone to helped me..

is there no any other solution using the basic codes i used in my source code?

like if, while, for, printf, etc..

actually our prof is still teaching us the basics.. but i cant figure out a way to put my program back to the main menu with the use of these basic codes

>uhhm.. if i use this, its clear that i asked someone to helped me..
Good. Then learn from it instead of blindly copying my code. All of the necessities are there if you take the time to understand what was done and why.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.