help why does my output table's came out that way even after i added the get line?
Please help why does my output table's came out that way even after i added the get line?
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// structure
struct Hat
{
string brand;
string color;
float price;
};// declare the structure variable
int main()
{
// declare an array of Hats of size 5
Hat hat[5];
int i;
cout<<"Welcome to Hats For U!\n";
/* loop to read values for 5 hats */
for(i=0;i<5;i++){
cout<<"Hat "<<(i+1)<<"\n";
cout<<"Enter the brand of hat: ";
cin>>hat[i].brand;
getline(cin,hat[i].brand);
cout<<"Enter the hat color: ";
cin>>hat[i].color;
cout<<"Enter the hat price(RM): ";
cin>>hat[i].price;
}
// display messages
cout<<"\n\nRECORD OF HATS \n";
cout<<"----------------------------------------------------------\n";
cout<<setw(35)<<left<<"Brand"<<setw(10)<<left<<"Color"<<setw(5)<<left<<"Price(RM)\n";
cout<<"----------------------------------------------------------\n";
/* loop to display values for 5 hats */
for(i=0;i<5;i++){
cout<<setw(35)<<left<<hat[i].brand;
cout<<setw(10)<<left<<hat[i].color;
cout<<setw(5)<<left<<hat[i].price<<endl;
}
return 0;
}
Step by step
Solved in 3 steps with 3 images