Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  atm machine
Language: C/C++
Code:
#include<stdio.h>
#include<iostream>
using namespace std;
int get200(int x,int n,int av100,int av200)
{
      int enough=1,outp=0;
      while(enough<av200)
      {
        int withamt1=n-enough*200;
        if((withamt1/100<=av100)&&(withamt1%100==0))
        { int op200=enough;
          int op100=withamt1/100;
         if((op100+op200)<=x)
         {
           outp=(op100+op200);
           break;
         }
         else
         enough++;
        }
        else
        enough++;
      }
      return outp;
}
int get500(int x,int n,int av100,int av200,int av500)
{
    int enough=1,outp=0;
    while(enough<av500)
    {
        int withamt1= n-enough*500;
        int withamt2=get200((x-enough),withamt1,av100,av200);
        if(withamt2>0)
        {   if(enough+withamt2<x)
            {
                outp=enough+withamt2;
                break;
            }
            else
            enough++;
        }
        else
        enough++;
    }
}
int get1000(int x,int n,int av100,int av200,int av500,int av1000)
{
    int enough=1,outp=0;
    while(enough<av1000)
    {
        int withamt1= n-enough*1000;
        int withamt2=get500((x-enough),withamt1,av100,av200,av500);
        if(withamt2>0)
        {   if(enough+withamt2<x)
            {
                outp=enough+withamt2;
                break;
            }
            else
            enough++;
        }
        else
        enough++;
    }
    
}
int main()
{ int n,withamt,ava100,ava200,ava500,ava1000;
    cin>>n;
    cin>>withamt;
    cin>>ava100;
    cin>>ava200;
    cin>>ava500;
    cin>>ava1000;
    int op100 = withamt/100;
     if(op100<=ava100)
     {
      if(op100<=n)
      cout<<op100;
     }
    else
     { int outp200=get200(n,withamt,ava100,ava200);
         if(outp200>0)
          cout<<outp200;
         else
         { int outp500=get500(n,withamt,ava100,ava200,ava500);
             if(outp500>0)
             cout<<outp500;
             else
             {
               int outp1000=get1000(n,withamt,ava100,ava200,ava500,ava1000);
              if(outp1000>0)
              cout<<outp1000;
               else
               cout<<0;
            }
         }
     }
}         
Comments: