Getting a code to pause


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main()
{
    int age;
    int name;
    int Lname;
    cout << "Enter your name" << endl;
    cin >> name;
    cout << "Enter your last name" << endl;
    cin >> Lname;
    cout << "Enter your age" << endl;
    cin >> age;


}


what im trying to do is get it to pause between cin entries, where as right now once i type my name it runs the rest of the code without allowing me to imput the rest of the information
What exactly are you typing when you respond to the input prompt? That is, can you show us what happens when you run the program?
i cant SHOW you, but i can type it
"
Enter your name
Mason
Enter your last name
enter your age

proccess returned 0 (0x0) Execution time :2.004 s
Press any key to continue."

that pops up when i run the code and type int he first variable, using Code Blocks if that makes any difference to you

It doesnt give me a chance to imput the other two variables, age and Lname
Last edited on
Oh, I didn't look hard enough.

You have given your "name" a type of int. Integers are numbers. When you type "Mason", the computer doesn't know what kind of number to make of that, and so it marks it as an error, and so all further attempts to read information are also errors and your program runs all the way to completion.

Use strings for textual information (like names), and ints for (integer) numbers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int age;
    string name;
    string Lname;
    cout << "Enter your name" << endl;
    cin >> name;
    cout << "Enter your last name" << endl;
    cin >> Lname;
    cout << "Enter your age" << endl;
    cin >> age;

    return 0;
}

Hope this helps.
Last edited on
Derp, guess we both make mistakes D=

i knew somewhere that int meant number ;)

works like a charm

thanks for the help,
Last edited on
Topic archived. No new replies allowed.