I'm working with structures, but somehow it skips one of the user inputs for the pie's price:
#include <iostream>
#include <windows.h>
#include <string>
#include <conio.h>
using namespace std;
const int ESC = 0x1b;
struct pie{
string brand;
float price;
string flavour;
}pies[5];
int main()
{
cout << "Structures.";
cout << "\nPress c to contine.";
int a;
while ( (a = getch()) != ESC)
if (a == 'c')
{
int n;
int g;
for (n = 0; n<5; n++)
{
cout << "\nEnter brand of pie:";
getline(cin,pies[n].brand);
cout << "\nEnter price of pie:";
cin >> g;
pies[n].price = g;
cout << "\nEnter Flavour of pie:";
getline(cin,pies[n].flavour);
}
getch();
return 0;
}
}
When I get up to Enter brand of pie, then I press enter, it skips straight onto Enter Flavour of pie leaving the price of pie blank. I've tried cin.ignore() but that doesn't seem to do it. Any help would be appreciated.:-/