getline command in C++
Alright, I'm writin my pogram but I gotta use a getline command and im not really positive on how to do it
My program looks like this so far:
#include <iostream>
#include <iomanip>
#include <string>
int main (void)
{
cout << "Welcome to Guaranteed Auto Insurance, Inc."
endl;
cout << "Please enter your age" endl;
cin >> age;
cout << "How many tickets have you received?"endl;
cin >> num;
if (16 < age < 90) && (ticket num < 4)
\tcout << "Oops! You failed our insurance policies!"<< endl;
else
{
\tif (ticket num = 0)
\tcout << rate
\t
\tif ( male && age < 25 )
\tcout << rate + (rate *.2)
\t
rate= .5*CarValue
string Sex;
cout << "What is your sex?"
cin >> Sex;
\tif ( male && 25 <= age >= 29 )
\tcout << rate + (rate*.1)
\t
\t\t
\tif (male && age > 29)
\tcout << rate
\t
\tif (female && age < 25)
\tcout >> rate + (rate * .1)
\t
\tif (female && 25 <= age >= 29)
\tcout << rate + (rate * .05)
\t
\tif (female > 29)
\tcout << rate
Anyone got ne ideas?
My program looks like this so far:
#include <iostream>
#include <iomanip>
#include <string>
int main (void)
{
cout << "Welcome to Guaranteed Auto Insurance, Inc."
endl;
cout << "Please enter your age" endl;
cin >> age;
cout << "How many tickets have you received?"endl;
cin >> num;
if (16 < age < 90) && (ticket num < 4)
\tcout << "Oops! You failed our insurance policies!"<< endl;
else
{
\tif (ticket num = 0)
\tcout << rate
\t
\tif ( male && age < 25 )
\tcout << rate + (rate *.2)
\t
rate= .5*CarValue
string Sex;
cout << "What is your sex?"
cin >> Sex;
\tif ( male && 25 <= age >= 29 )
\tcout << rate + (rate*.1)
\t
\t\t
\tif (male && age > 29)
\tcout << rate
\t
\tif (female && age < 25)
\tcout >> rate + (rate * .1)
\t
\tif (female && 25 <= age >= 29)
\tcout << rate + (rate * .05)
\t
\tif (female > 29)
\tcout << rate
Anyone got ne ideas?
Comments
only what you get has to be a string not a variable i believe
all part of istreams
check that url....
enjoy
pete
\tcout << "Enter your name: ";
\tgetline (cin, name);
Where name was an apstring.
This was in C++ for DOS, which is what they MADE us use when I took c++ last year.
It could be also getline(cin, whatever), I forget.
I think when you use getline though, that it leaves the eol character in the istream, so to get rid of it to get ready for the next input, you have to call cin.get() after your getline call to get rid of that eol character.