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?
//Simple script.
#include <iostream>
usingnamespace 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)
}
#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
constint 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
}