Need some advise with program

This is a discussion on Need some advise with program within the C++ Programming forums, part of the General Programming Boards category; This program prints out a check. We had to write a function for digits 5,4,3 and a function for cents. ...

  1. #1
    Unregistered
    Guest

    Exclamation Need some advise with program

    This program prints out a check. We had to write a function for digits 5,4,3 and a function for cents. I'm having trouble in two areas of the program. One is my teens are not printing out right, like instead of twelve I get ten two ect.
    I've tried alot of different things but nothing has worked so far. Its probably something simple, but I just can't see it. The other problem is printing the amount out on the check, etc. $600.00, it prints the cents sometimes and sometimes not, depending upon the amount you entered if it has cents or not. If anyone has any suggestions, I would deeply appreicate it.

    Here is the code:#include <iostream.h>
    #include <iomanip.h>
    #include <math.h>

    //Check writing program, Final Test, CIS
    //This program will write out the amount and pay to, date of a check when the amount is entered
    //Date:12/13/01

    void cents(int,int);
    void WriteD3 (int);
    void WriteD4 (int);
    void WriteD5 (int);

    int main()
    {

    int xamt=0,d1=0,d2=0,d3=0,d4=0,d5=0;
    float amt;



    cout << " Input the check amount and press enter: ";
    cin >> amt;
    cout << "_________________________________________________ ______________________________\n\n\n"<<endl;

    cout << setw(45) << __DATE__ << endl;

    cout << (" ") << endl;

    cout << " WalMart " << " "<< " $ "<< amt << " " << endl; //THERE IS SOMETHING WRONG HERE WITH PRINTING OUT THE AMOUNT
    //LIKE $600.00, THE OLD LINE WON'T PRINT ANYTHING. STILL WORKING ON
    //THE TEEN PROBLEM!

    cout << " " << endl;
    cout << endl;

    if (amt <= 1000.00)
    {
    xamt=amt * 100;
    d1=xamt%10;
    d2=xamt%100/10;
    d3=xamt%1000/100;
    d4=xamt%10000/1000;
    d5=xamt%100000/10000;
    }
    WriteD5 (d5);
    WriteD4 (d4);
    WriteD3 (d3);
    cents(d1,d2);



    return 0;
    }

    void cents(int d1, int d2)
    {
    cout << " Dollars and ****************** " << " " << d2 << d1 << " /100 " << endl;
    cout << "\n\n\n" << endl;
    return ;
    }


    void WriteD5(int d5)

    {
    switch(d5)
    {case 1:
    cout <<" One Hundred ";
    break;
    case 2:
    cout << " Two Hundred ";
    break;
    case 3:
    cout << " Three Hundred ";
    break;
    case 4:
    cout << " Four Hundred ";
    break;
    case 5:
    cout << " Five Hundred ";
    break;
    case 6:
    cout << " Six Hundred ";
    break;
    case 7:
    cout << " Seven Hundred ";
    break;
    case 8:
    cout << " Eight Hundred ";
    break;
    case 9:
    break;
    default: cout << " " ;


    return ;

    }
    }


    void WriteD4 (int d4)

    {
    int d3=0;


    switch(d4)
    {case 1:
    if(d3==0)
    cout<<"ten ";
    else if(d3==1)
    cout<<"eleven ";
    else if(d3==2)
    cout<<"twelve ";
    else if(d3==3)
    cout<<"thirteen ";
    else if(d3==4)
    cout<<"fourteen ";
    else if(d3==5)
    cout<<"fifteen ";
    else if(d3==6)
    cout<<"sixteen ";
    else if(d3==7)
    cout<<"seventeen ";
    else if(d3==8)
    cout<<"eighteen ";
    else if(d3==9)
    cout<<"nineteen ";
    break;
    case 2:
    cout<<"Twenty-";
    break;
    case 3:
    cout<<"Thirty-";
    break;
    case 4:
    cout<<"Forty-";
    break;
    case 5:
    cout<<"Fifty-";
    break;
    case 6:
    cout<<"Sixty-";
    break;
    case 7:
    cout<<"Seventy-";
    break;
    case 8:
    cout<<"Eighty-";
    break;
    case 9:
    cout<<"Ninety-";
    break;
    default:;

    return ;

    }
    }

    void WriteD3 (int d3)
    {
    int d4=0;
    switch(d3)
    {
    case 1:
    if(d4 !=1)
    cout<<"one ";
    break;
    case 2:
    if(d4!=1)
    cout<<"Two ";
    break;
    case 3:
    if(d3!=1)
    cout<<"Three ";
    break;
    case 4:
    if(d4 !=1)
    cout<<"Four ";
    break;
    case 5:
    if(d4 !=1)
    cout<<"Five ";
    break;
    case 6:
    if(d4 !=1)
    cout<<"Six ";
    break;
    case 7:
    if(d4 !=1)
    cout<<"Seven ";
    break;
    case 8:
    if(d4 !=1)
    cout<<"Eight";
    break;
    case 9:
    if(d4 !=1)
    cout<<"Nine ";
    break;
    default:
    cout<<" ";
    return;
    }
    }

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Code:
    cout << setw(45) << __DATE__ << endl; 
    
    cout << (" ") << endl;
    1. why do u have parenthesis?? Does the date macro work on ur compiler? It is not on every one.





    2. If the amount of money is greater than 1000, are the values of d(whatever) ever set???



    3. When u do set the values of d(whatever), use parenthesis to clarify ur code, it might have an impact(not sure).

  3. #3
    Unregistered
    Guest
    No the date marco does not work on my compiler. it is just a tutorial version. I have worked on the program some more and I think I have it figured out now. Thanks for the information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21