Need some help w/program

This is a discussion on Need some help w/program within the C++ Programming forums, part of the General Programming Boards category; This is an assignment in my c++programming class. The assignment was to write a program that will print out a ...

  1. #1
    Unregistered
    Guest

    Need some help w/program

    This is an assignment in my c++programming class. The assignment was to write a program that will print out a check like some department stores use when you check out. I have a problem with the program printing out 100.00 to 109.00. Its prints the written amout below the line where it is suppose to go. It only does this with the above mention amounts. Also we have to use the system date and I don't know if thats right or not either. I have a few warnings also. Any info would help greatly.This is my first class working with c++ programming.

    #include <iostream.h>
    #include <iomanip.h>
    #include <math.h>

    int main()
    {const char x=20;
    char h[x],t[20],o[5];

    double amt;
    long tamt, d1,d2,d3,d4,d5;

    cout << " Input the check amount and press enter: ";
    cin >> amt;
    if (amt <= 1000.00)
    {
    tamt=amt*100;
    d1=tamt%10;
    d2=tamt%100/10;
    d3=tamt%1000/100;
    d4=tamt%10000/1000;
    d5=tamt%100000/10000;

    cout << "_________________________________________________ ______________________________\n\n\n"<<endl;

    cout << setw(45) << (" Date %s\n",__DATE__) << endl;

    cout << (" ") << endl;

    cout << " Pay: " << " WalMart " << " "<<setw(7) << setiosflags(ios::fixed||ios::showpoint) << setprecision(2) << "$" << d5 << d4 << d3 << "." << d2 << d1 << endl;

    cout << " " << endl;
    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:
    cout << " Nine Hundred ";
    break;
    default: cout << " " <<endl;
    }
    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: cout << " " << endl;
    }
    switch (d3)
    {
    case 1:
    if(d4 !=1)
    cout << " One ";
    break;
    case 2:
    if(d4 !=1)
    cout << " Two ";
    break;
    case 3:
    if(d4 !=1)
    cout << " Three";
    break;
    case 4:
    if(4 !=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 << " ";
    }
    }
    cout <<"Dollars and **************" <<d2<<d1<<"/"<<100 <<endl;
    cout << "_________________________________________________ ________________" <<endl;




    return 0;


    }

  2. #2
    Unregistered
    Guest

    didn't have to look far(no offense)

    Make your const char x=20 const in x=20

  3. #3
    Unregistered
    Guest
    No offense taken, but I don't know if I understand what you mean! Is const in part of the ios class? We haven't cover that in class so I'm not sure about it. It has something to do with input/output doesn't it or not?

  4. #4
    Unregistered
    Guest
    const char x=20;
    char h[x],t[20],o[5];

    in line one above you declare x to be of type const char, whereas in line two above you try to use x as an int. This likely will lead to problems. If you change x to be of const int rather than const char it makes more sense. const is a keyword like for, while, int, char, etc.

    However, since I can't see where you use h, t, or o anyway, it's not a problem at the moment.

    The reason you have a printing problem for values like 109.00 is that the in if d4 is 0 your case statement handles it in the default case which prints out a newline because it contains a call to the endl; manipulator as part of the statement. Drop the endl like you have in the switch(d3) set and see what happens. The same holds for the switch(d5) default statement by the way.

    functions that handle time are located in time.h or ctime. They usually return results in a struct of some sort. You compiler can help tell you what struct is used and which fields you need to extract to get the data you want for your program. I would look up systemTime(), localTime() in your on line help section to get started as I don't remember the details at this point.

  5. #5
    Unregistered
    Guest

    Thumbs up

    Thank you so much. I made the changes you suggested and it works the way it is suppose to. Thank you for taking the time to look at my program and giving me advise.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help ASAP w/program
    By CindyLou in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2002, 07:36 PM
  2. having problems w/program
    By Stephanie in forum C Programming
    Replies: 5
    Last Post: 02-04-2002, 03:14 PM

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