hi i got a problem when try to use pointer and struct..somehow ive manage to compile my coding but the main prob is that the output is not what ive keyed in..
#include <iostream>
#include <conio>
#include <string>
#include <stdlib>
void printtable();
void input();
void calculate ();
void scorecard();
void print();
struct info
{
char name[40];
char buggie;
char dine;
char membership;
char side;
int totalhit;
int price;
};
main()
{
printtable();
input();
calculate ();
print();
system ("pause");
}
void printtable()
{
string pricetable[3][3]={{"RM 30","RM 40","RM 15"},{"RM 25","RM 30","RM 10"},{"RM 20","RM 25","RM 10"}};
cout<<"\t\tMember"<<"\t\t"<<"Non"<<"\t\t"<<"Student"<<endl;
for (int row=0;row<3;row++){
if (row==0)
cout<<"Play cost\t";
else if (row==1)
cout<<"Buggie\t\t";
else if (row==2)
cout<<"Eat in\t\t";
for (int col=0;col<3;col++)
cout<<pricetable[row][col]<<"\t\t";
cout<<endl;}
}
void input()
{
info customer;
info *anew;
anew=&customer;
cout<<"Input Name : ", cin.getline (anew->name,40);
cout<<"Input Membership type : ", cin>>anew->membership;
cout<<"Rent Buggie? (Y/N) : ", cin>>anew->buggie;
cout<<"select side. (E/W) : ", cin>>anew->side;
cout<<"dine in? (Y/N) : ", cin>>anew->dine;
}
void calculate ()
{
info customer;
info *anew;
anew=&customer;
if (anew->membership=='m'){
if (anew->buggie=='y')
if (anew->dine=='y')
anew->price=30+25+20;
else
anew->price=30+25;
else if (anew->buggie=='n')
if (anew->dine=='y')
anew->price=30+20;
else
anew->price=30;}
else if (anew->membership=='n'){
if (anew->buggie=='y')
if (anew->dine=='y')
anew->price=40+30+25;
else
anew->price=40+30;
else if (anew->buggie=='n')
if (anew->dine=='y')
anew->price=30+25;
else
anew->price=30;}
else if (anew->membership=='s'){
if (anew->buggie=='y')
if (anew->dine=='y')
anew->price=15+10+10;
else
anew->price=15+10;
else if (anew->buggie=='n')
if (anew->dine=='y')
anew->price=15+10;
else
anew->price=15;}
cout<<anew->price;
scorecard();
}
void scorecard ()
{
info customer;
info *anew;
anew=&customer;
int scorecard[9][3],z=0;
for (int col=0;col<1;col++)
for (int row=0;row<9;row++)
scorecard[row][col]=z++;
for (int col=1;col<2;col++){
scorecard[0][1]=3;
scorecard[1][1]=4;
scorecard[2][1]=3;
scorecard[3][1]=4;
scorecard[4][1]=5;
scorecard[5][1]=3;
scorecard[6][1]=5;
scorecard[7][1]=4;
scorecard[8][1]=4;}
for (int row=0;row<9;row++){
cout<<"input score : ";
cin>>scorecard[row][2];
anew->totalhit=anew->totalhit+scorecard[row][2];}
cout<<"Hole"<<"\t\t"<<"par"<<"\t\t"<<"player"<<endl;
for (int row=0;row<9;row++){
for (int col=0;col<3;col++)
cout<<scorecard[row][col]<<"\t\t";
cout<<endl;}
}
void print()
{
info customer;
info *anew;
anew=&customer;
cout<<"Name : "<<anew->name<<endl;
cout<<"Membership : "<<anew->membership<<endl;
cout<<"No of Holes played : "<<9<<endl;
cout<<"Total Hit : "<<anew->totalhit<<endl;
cout<<"Side Of Course : "<<anew->side<<endl;
cout<<"transport : "<<anew->buggie<<endl;
cout<<"Price : "<<anew->price<<endl;
}
sorry for the bad coding..more detail,anew->price, anew->buggie & totalhit in print() function didnt display the value it suppose to display..help, ive been trying to troubleshoot for 3 days now but no luck -_-