Thread: Debug error, help needed

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    1

    Debug error, help needed

    Seems to have this Debug error when i try to run it, not sure how to solve.


    Code:
    #include <iostream>
    using namespace std;
    double everything;
    float a;
    float b;
    inline void balance(void)
    
    
        {
        cout<<"You have a total of: Lm"<<everything;
    }
    
    inline void intro(void)
    
    
        {
        cout<<"~~~~BANK ACCOUNT ORGANIZER~~~~\n";
        cout<<"\nBank Account Organizer will organize your bank account. You can withdraw money from your bank account or you may also choose to deposit money into your bank account. \nYou can check your account balance if you need to do so!\n";
    }
    
    inline void balancenote(void)
    
    
        {
        int money;
        int five2;
        int one;
        int five;
        int ten;
        double cent;
        money=everything;
        ten = money/10;
        five = money%10;
        five2 = five/5;
        one = five%5;
        cout << "\nYou have:\n";
        cout << "Lm10: " << ten;
        cout << "\nLm5: " << five2;
        cout << "\nLm1: " << one;
        cout << "\nLm0.50: " << (everything - money)*2;
    }
    
    int main()
    
    
        {
        intro();
        cout<<"\nPlease enter your full name: ";
        char name[20];
        cin.getline(name,20,'\n');
        cout<<"\n"<<name<<" Bank Account:";
        cout<<"\n";
        int n;
        while (n!=0)
    
    
            {
            cout<<"\n\nPlease choose: \n1)Withdraw money from your bank account\n2)Deposit money into your bank account\n3)Check your account balance\n4)Empty your account\nPress 0 to quit!";
            cin>>n;
            switch (n)
    
    
                {
                case 1:
                cout<<"\nPlease choose the amount you would like to withdraw:";
                cout<<"\n1)Lm5\n2)Lm10\n3)Lm20\n4)Lm50\n5)Lm100\n6)Other...\n";
                cin>>b;
                if (b==1)
    
    
                    {
                    if (5>everything)
    
    
                        {
                        cout<<"\nThe transaction cannot be done. There isn't enought money in your account";
                    }
    
                    else
    
    
                        {
                        everything = everything - 5;
                        cout<<"\nThe transaction is complete! - You have successully withdrawn Lm5!";
                    }
    
                }
    
                else if (b==2)
    
    
                    {
                    if (10>everything)
    
    
                        {
                        cout<<"\nThe transaction cannot be done. There isn't enought money in your account";
                    }
    
                    else
    
    
                        {
                        everything = everything - 10;
                        cout<<"\nThe transaction is complete! - You have successully withdrawn Lm10!";
                    }
    
                }
    
                else if (b==3)
    
    
                    {
                    if (20>everything)
    
    
                        {
                        cout<<"\nThe transaction cannot be done. There isn't enought money in your account";
                    }
    
                    else
    
    
                        {
                        everything = everything - 20;
                        cout<<"\nThe transaction is complete! - You have successully withdrawn Lm20!";
                    }
    
                }
    
                else if (b==4)
    
    
                    {
                    if (50>everything)
    
    
                        {
                        cout<<"\nThe transaction cannot be done. There isn't enought money in your account";
                    }
    
                    else
    
    
                        {
                        everything = everything - 50;
                        cout<<"\nThe transaction is complete! - You have successully withdrawn Lm50!";
                    }
    
                }
    
                else if (b==5)
    
    
                    {
                    if (100>everything)
    
    
                        {
                        cout<<"\nThe transaction cannot be done. There isn't enought money in your account";
                    }
    
                    else
    
    
                        {
                        everything = everything - 100;
                        cout<<"\nThe transaction is complete! - You have successully withdrawn Lm100!";
                    }
    
                }
    
                else if (b==6)
    
    
                    {
                    cout<<"\nPlease enter the amount:";
                    float g;
                    cin>>g;
                    if (g>everything)
    
    
                        {
                        cout<<"\nThe transaction cannot be done. There isn't enought money in your account";
                    }
    
                    else
    
    
                        {
                        everything = everything - g;
                        cout<<"\nThe transaction is complete! - You have successully withdrawn Lm"<<g<<"!";
                    }
    
                }
    
                break;
                case 2:
                cout<<"\nPlease enter the amount you would like to put into your bank account.";
                cin>>a;
                everything = everything + a;
                cout<<"\nThe transaction is complete! - You have successully put Lm"<<a<<" into your bank account!";
                cout<<"You now have Lm"<<everything<<". Check your account balance for more info.";
                break;
                case 3:
                cout<<"\nHere's your balance:";
                balance();
                balancenote();
                break;
                case 4:
                everything = 0;
                cout<<"\nYour account has been emptied";
                break;
                case 0:
                break;
                default:
                cout<<"\nYou have pressed the wrong number!";
            }
    
        }
    
        char q;
        do
    
    
            {
            cout<<"\nThanks for using BANK ACCOUNT ORGANIZER! Press Q to quit!";
            cin>>q;
            if (q=='q' || q=='Q')
            return 0;
        }while (q!='q' && q!='Q');
    
    }

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    I don't know what do you mean by Debug Error but your program has a little problem that is if you enter a character instead of a number it fails. It is because you should place this code after each input:
    Code:
    if(!cin.good()){
          cin.clear();
          cin.ignore(300,'\n');
          //.....Ask user to enter a number....
    }
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    12
    It seems you are using an un-initialized n here:

    Code:
    int n;
    while (n!=0)
    {
        . . .
    }
    Probably it should be

    Code:
    int n;
    do
    {
        . . .
    } while(n != 0);
    I hope this helps.

  4. #4
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    It seems you are using an un-initialized n here:...
    I was lucky that program worked without problem for me.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    You cannot do this if (5>everything).

    5 is a literal. It is also a rvalue (right-value). It should go on the other side of the logical expression. if(everything <= 5)
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    5 is a literal. It is also a rvalue (right-value). It should go on the other side of the logical expression. if(everything <= 5)
    Why?
    (everything <= 5) ==(5>=everything) no?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Actually it's a total silliness what I said. I'm obviously wrong. Besides the rvalue or lvalue meanings are only to be seen in the context of assignment.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    EDIT: already mentioned by siavoshkc.

    But seriously, using double to represent 1/100 values are a VERY BAD IDEA. Why. For small amounts, you could use an int or long divided by 100, for larger transactions you could use a 64-bit integer (even Gates isn't that rich ).
    Last edited by jafet; 08-11-2006 at 11:15 PM.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  9. #9
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by Mario F.
    You cannot do this if (5>everything).

    5 is a literal. It is also a rvalue (right-value). It should go on the other side of the logical expression. if(everything <= 5)
    I disagree.. I always put constant or literal values on the left-hand side of logical expressions whenever possible. for one simple reason, that i'm merely human, and sometimes, i make this stupid mistake..
    Code:
    if ( somevar = 5 ) // graaaarghhhhh!
    then at least the compiler will whack me around the head if i type
    Code:
    if ( 5 = somevar ) // Compiler error.. phew!!

  10. #10
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    Quote Originally Posted by Mario F
    Actually it's a total silliness what I said. I'm obviously wrong. Besides the rvalue or lvalue meanings are only to be seen in the context of assignment.
    Anyway this mistake should not happen.
    [edit]
    I mean using = instead of ==.

    [edit2]
    I always put constant or literal values on the left-hand side of logical expressions whenever possible.
    Intresting point.
    Last edited by siavoshkc; 08-11-2006 at 06:04 PM.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  11. #11
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by siavoshkc
    Anyway this mistake should not happen.
    [edit]
    I mean using = instead of ==.

    [edit2]


    Intresting point.
    Heh, it's one of those "d'uh! I can't believe I made that mistake" bugs

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary not built with debug info - why?
    By ulillillia in forum C Programming
    Replies: 15
    Last Post: 12-11-2008, 01:37 AM
  2. makefiles - debug & release?
    By cpjust in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 04:00 PM
  3. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 11:08 AM
  4. Debug help needed
    By Achy in forum C Programming
    Replies: 3
    Last Post: 11-16-2005, 03:27 PM
  5. Ask about Debug Assert Failed
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2002, 11:07 PM