cout << "What is your name?" << "\n" << endl;
cin >> name;
cout << "Have you got a full drivers license?" "\n" << endl;
cin >> drivinglicense;
cout << "what is your address?" << "\n" << endl;
cin >> address;
cout << "what is your telephone number?"<< "\n" << endl;
cin >> telephoneNumber;

When I enter a letter it skips all questioins and I don't know how to fix this?
Help please

This is the code I have written but I unable to input letters.
Help please?

#include <iostream>
#include <cstdlib>
#include <iostream>
#include <string>

char carChoice;
int random_integer = rand();
int pricePerDay;
int daysOfHire;
int totalCost;
int age;
char name;
char address;
int telephoneNumber;
char drivinglicense;

using namespace std;

int main()

{
    cout << "Royal Rentals" << endl;
    cout << "---------------------------------------------"<<"\n" <<endl;
    cout << "Current Stock: " <<endl;
    cout << "A - Lamborghini Aventador" <<endl;
    cout << "B - Lamborghini Huracan" <<endl;
    cout << "C - Mercedes Benz AMG GT S" <<endl;
    cout << "D - Audi R8 V10" <<endl;

cout << "Which car would you like to rent (A, B, C or D)" << "\n" << endl;
cin >> carChoice;
cout << "How many days would you like to hire the car for" << "\n" << endl;
cin >> daysOfHire;
cout << "How old are you?" << "\n" << endl;
cin >> age;

if (age < 21)
{
    cout << "Sorry but you have to over the age of 21 to hire our super cars" << "\n" << endl;
    cout << "Please close the program to hire a car suitable for your age" << "\n" << endl;
    exit (0);
}

cout << "What is your name?" << "\n" << endl;
cin >> name;
cout << "Have you got a full drivers license?" "\n" << endl;
cin >> drivinglicense;
cout << "what is your address?" << "\n" << endl;
cin >> address;
cout << "what is your telephone number?"<< "\n" << endl;
cin >> telephoneNumber;

if (carChoice == 'a')
{
    totalCost = daysOfHire * 685;
    cout << "You have chosen the following car for hire: Lamborghini Aventador" << endl;
    cout << "The price per day is 685.00 GBP" << endl;
    cout << "The Total Cost is: " << totalCost << endl;
    cout << "Invoice Number; " << random_integer << endl;
}
else if (carChoice == 'b')
{
    totalCost = daysOfHire * 585;
cout << "You have chosen the following car for hire: Lamborghini Huracan" << endl;
cout << "The price per day is �585.00 GBP" << endl;
cout << "The Total Cost is: " << totalCost << endl;
cout << "Invoice Number; " << random_integer << endl;
}
else if (carChoice == 'c')
{
    totalCost = daysOfHire * 485;
cout << "You have chosen the following car for hire: Mercedes Benz AMG GT S" << endl;
cout << "The price per day is �485.00 GBP" << endl;
cout << "The Total Cost is: " << totalCost << endl;
cout << "Invoice Number; " << random_integer << endl;
}
else if (carChoice == 'd')
{
    totalCost = daysOfHire * 445;
cout << "You have chosen the following car for hire: Audi R8 V10" << endl;
cout << "The price per day is �445.00 GBP" << endl;
cout << "The Total Cost is: " << totalCost << endl;
cout << "Invoice Number; " << random_integer << endl;
}
else
{
cout << "You have entered an invalid response" << endl;
}
}

Look at the datatype you used for name. It's char. That's no moon (or string.)

You have to declare your strings to have enough space to hold the longest expected string. Since you declared only one char for name (for example), any unused input chars are used to fill input requests for the other input variables. Try something like char[50] for name, etc. As written, if I entered "Jim" for name I would get the following results:

name = "J"
drivinglicense = "i"
address = "m"

Another issue is your use of "\n" << endl; for end-of-lines. Leave out the "\n" the endl will deal with that for you. Common beginner mistake with C++ string output. Remember that endl will also flush the output stream. You only need the extra new-line if you want your output to have extra spaces.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.