getline command in C++

Posted:
in Genius Bar edited January 2014
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?

Comments

  • Reply 1 of 4
    ast3r3xast3r3x Posts: 5,012member
    isn't it getch();?



    only what you get has to be a string not a variable i believe
  • Reply 2 of 4
  • Reply 3 of 4
    dogcowdogcow Posts: 713member
    This may have to do with the complier, but I used getline like this:



    \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.
  • Reply 4 of 4
    mcqmcq Posts: 1,543member
    I think you can use getline in all the places you have cin >> whatever, by cin.getline(whatever);



    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.
Sign In or Register to comment.