Results 1 to 3 of 3

Thread: [RESOLVED] C++ program runs but i get garbage as an output

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    34

    Resolved [RESOLVED] C++ program runs but i get garbage as an output

    Im using visual c++ 6.0

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <string.h>
    
    class customer
    {
    private:
    	char cardname[20];
    	float creditlimit;
    	float amountspent;
    	float amountleft;
    	calculate();
    	
    	
    	
    public:
    	void input();
    	void output();
    	
    };
    
    void customer::input()
    {
    	cout<<"Please enter the card name: ";
    	cin>>cardname;
    	cout<<"Please enter the credit limit: ";
    	cin>>creditlimit;
    	cout<<"Please enter the amount spent: ";
    	cin>>amountspent;
    }
    
    customer::calculate()
    {
    	
    	amountleft = creditlimit - amountspent;
    	
    }
    
    void customer::output()
    {
    
    	cout<<"Thank you "<<cardname<<" you have "<<amountleft<<" left.";
    }
    
    void main()
    {
    	customer c1;
    	c1.input();
    	c1.output();
    	getch();
    }
    for example if i put the credit limit at 500 and the amount spent at 200 i get asdfasdf123123!@+800 for an answer

    any ideas?

  2. #2
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    Re: C++ program runs but i get garbage as an output

    Code:
    void customer::input()
    {
    	cout<<"Please enter the card name: ";
    	cin>>cardname;
    	cout<<"Please enter the credit limit: ";
    	cin>>creditlimit;
    	cout<<"Please enter the amount spent: ";
    	cin>>amountspent;
    	calculate();
    }

  3. #3
    Junior Member
    Join Date
    Sep 2006
    Posts
    28

    Re: C++ program runs but i get garbage as an output

    Heh, I noticed that too. Its just displaying the contents of the unset variable, it doesn't actually calculate amountleft.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width