how can I print a char array in c++ -
i working on simple hotel reservsation project couldn't print customer name , payment type after entering names'. here piece of code typed.
cout << "please enter customer name: " << endl; cin >> customername1; cin.getline(customername1,100,'\n'); fflush(stdin); cout << "please enter payment type: " << endl; cin >> paymenttype; cin.getline(paymenttype,100,'\n'); fflush(stdin); cout << "how many days stay: " << endl; cin >> days; room_income = days * 30; count_room++ ; count_customer1++ ; customer_name1[single]= new char [strlen(customername1)+1]; strcpy(customer_name1[single],customername1); payment_type[single]= new char [strlen(paymenttype)+1]; strcpy(payment_type[single],paymenttype); cout << "room number : " << single << endl<< endl; cout << "customer name : "<< customer_name1 << endl << endl; cout << "payment type : "<< payment_type << endl<< endl; cout << "number of day accomodation :"<< days << endl<< endl; cout << "income room : "<< room_income<< endl<< endl;
some random numbers , letters displayed customer name , payment type. how can write them properly?
for customer name , payment type, try print array, instead of 1 element. since array pointer first element, 'random number', memory address.
try:
cout << "customer name : "<< customername1 << endl << endl; cout << "payment type : "<< paymenttype << endl<< endl;
and when you've got working, follow comments , std::string , vectors...
Comments
Post a Comment