|
-
Sep 26th, 2006, 09:56 PM
#1
Thread Starter
Member
[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?
-
Sep 26th, 2006, 11:19 PM
#2
Frenzied Member
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();
}
-
Sep 27th, 2006, 01:51 AM
#3
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|