Help Please. Basic function not working

Hi guys,

Having a little trouble understanding why this will not work.

Basically i have 3 cout and 3 cin's and after i enter the first one it skips the last two and doesnt let me enter anything.

Here is the code:

#include "stdafx.h"
#include <iostream>
using namespace std;



int main()
{
int name;
int seats;
int totalseats;
float cost = 4.23456;
float totalcost = 4.23456;
{
cout << "Please enter your name: " << endl;
cin >> name;
cout << "Please enter the amount of seats you require: " << endl;
cin >> seats;
cout << "Please enter the cost per seat: " << endl;
cin >> cost;

}



return 0;
}


Basically all it is doing is inputting the name and then coming straight up with the last two couts and not asking me to input there values.

Thanks for any help in advance
Working fine: http://gm4.in/i/d7d.png
You aren't trying to enter letters in int name, are you?
Give example, you can't use spaces with cin, the way you wrote it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>
using namespace std;

int main()
{
    //int name;
    string name ; // name is a string ( #include <string> )

    int seats;
    float cost = 4.23456;

    {
        cout << "Please enter your name: " ;
        //cin >> name ; // read a name containing no white spaces
        std::getline( cin, name ) ; // read one complete line as the name

        cout << "Please enter the amount of seats you require: " ;
        cin >> seats ;

        cout << "Please enter the cost per seat: " ;
        cin >> cost;

    }

    // ...

}
Topic archived. No new replies allowed.