Hye there. Im working on a program, but it seems not working like i wanted to. Below is the code
The first few lines work well, but until enter price and enter discount, it skip and i can not type in the price and discount. It straightly printed out everything and the original price and discounted price showed sumthing like -1.(numbers)e+(numbers) When i compiled it, it didnt state any errors. So ima lil bit confuse here. Hope someone can help me with this, and so sorry if my question seems stupid. I am new in this C++ programming..Code:class Books { string isbnNo, description, title, author; float price, discountedprice, discountperc; public : void set_Data() { cout<<"Enter ISBN \t\t: "; getline(cin,isbnNo); cout<<"Enter Title \t\t: "; getline(cin,title); cin.ignore(); cout<<"Enter Description \t: "; getline(cin,description); cout<<"Enter Author's name \t: "; getline(cin,author); cin.ignore(); cout<<"Enter price \t\t: RM "; cin>>price; cout<<"Enter discount (%) \t: "; cin>>discountperc; } void calcDiscountedPrice() { discountedprice = price - (discountperc / 100 * price); } void print() { cout<<endl; cout<<"ISBN : "<<isbnNo<<endl; cout<<"Title : "<<title<<endl; cout<<"Description : "<<description<<endl; cout<<"Author : "<<author<<endl; cout<<"Original Price : RM "<<price<<endl; cout<<"Discounted Price : RM "<<discountedprice<<endl; } }; void func(Books*); void main() { Books B1; func(&B1); } void func(Books *add) { add->set_Data(); add->calcDiscountedPrice(); add->print(); }
Thank you..



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.
Friend of newbies, regulars and kings alike.