MVSE13 Problem!

I am using Microsoft Visual Studio 2013 (MVS13), I already tested this script and it works! The problem is the window closes to soon after I input my age. I already have the "cin.get ();" part added. Help pls?

PS: I am using the "Local Window Debugger"

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
29
30
//Simple script. 

#include <iostream>
using namespace std;

int main() //Main script.
{
	int age; int driverL; // All ints

	cout << "What is your age? \n"; //Ask your age.

	cin >> age; //input

	cout << "Only, " << age << " years old? \n"; //output

	if (age < 16) // check if use is older than 16.
	{
		driverL = 16 - age; //Sets years until driver license is earnable.

		cout << "only " << driverL << " years until you can drive!"; //output.
		
	}
	else{

		cout << "you are old enough to drive!"; // output. 
		
	}

	cin.get(); return 0; // fin, end, over, the end, final, close, you name it its done! (lol)
}
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
29
30
31
#include <iostream>
// using namespace std; // best avoided; just use std::cout etc.

int main() //Main script.
{
    // int age; int driverL; // All ints

    std::cout << "What is your age? "; //Ask your age.

    int age ;
    std::cin >> age; //input

    std::cout << "Only, " << age << " years old? \n"; //output

    if (age < 16) // check if use is older than 16.
    {
        // driverL = 16 - age; //Sets years until driver license is earnable.
        // postpone variable definition till we know how to initialise it
        const int years_to_wait = 16 - age; // favour semantically rich names
        std::cout << "only " << years_to_wait << " years until you can drive!\n"; //output.
    }
    else // { // favour a consistent brace style
    {
        std::cout << "you are old enough to drive!\n"; // output.
    }

    // throw away the remaining characters (typically a new-line) in the input buffer
    std::cin.ignore( 1000, '\n' ) ;
    std::cout << "press enter to quit... " ;
    std::cin.get(); // and wait for the user to press enter
}
or just use

control-f5

start your project.
Topic archived. No new replies allowed.