Thread: Cheque Printing Program Query

  1. #16
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    You just try to understand the code line-by-line so you can prove you did it yourself.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  2. #17
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Replace that line with something like this:
    So you replace a good solution with a bad one? Woohoo! You know, if you had just included <limits> and <ios> to begin with (as you should have), it wouldn't have been an issue.
    My best code is written with the delete key.

  3. #18
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Well, I don't know about other compilers. I only have to use <iostream> for that to work.

    karlawarla, try with including <limits> and <ios> then and put this line back there:
    Code:
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #19
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I only have to use <iostream> for that to work.
    A lot of things "work". Only a small subset of those things are "correct". This is precisely the situation we try to avoid by being anal about standards.
    My best code is written with the delete key.

  5. #20
    c++ beginner so be nice! karlawarla's Avatar
    Join Date
    Nov 2006
    Location
    West London, UK
    Posts
    33
    sorry i'm not familiar with what <limits> and <ios> are exactly?

  6. #21
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Just try this:
    Code:
    #include <iostream>
    #include <limits>
    #include <ios>
    
    char numbers[][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    char numbers2[][10]={"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eightteen","nineteen"};
    char numbers3[][10]={"","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
    void units(int u);
    
    int main(){
        units(68);
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
    }
    
    void units(int u){
        if(u==0){
            std::cout<<numbers[0];
            return;
        }
        int nums[3]={0,0,0};
        bool plusand=false;
        nums[0]=(u/100)%10;
        nums[1]=(u/10)%10;
        nums[2]=u%10;
        for(int x=0;x<3;x++){
            if(nums[x]>0){
                if(plusand){
                    std::cout<<"and ";
                    plusand=false;
                }
                if(x==0){
                    std::cout<<numbers[nums[0]]<<" hundred ";
                    plusand=true;
                }
                else if(x==1){
                    if(nums[1]==1){
                        std::cout<<numbers2[nums[2]];
                        break;
                    }
                    else{
                        std::cout<<numbers3[nums[1]]<<" ";
                    }
                }
                else{
                    std::cout<<numbers[nums[2]];
                }
            }
        }
        return;
    }
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  7. #22
    c++ beginner so be nice! karlawarla's Avatar
    Join Date
    Nov 2006
    Location
    West London, UK
    Posts
    33
    it just comes back with 'no such file or directory' :-s

  8. #23
    c++ beginner so be nice! karlawarla's Avatar
    Join Date
    Nov 2006
    Location
    West London, UK
    Posts
    33
    nope still not working, it was working before you said about the limits and ios.

  9. #24
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Then use the previous code.

    Anyway this should be the standard way and it seems you're missing some important headers.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  10. #25
    c++ beginner so be nice! karlawarla's Avatar
    Join Date
    Nov 2006
    Location
    West London, UK
    Posts
    33
    okay thanks, i will ask my lecturer about the headers, and hopefully i'll understand the code more.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing a program
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-09-2006, 07:25 AM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Crossword Puzzle Program
    By Loctan in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2006, 11:08 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM