Thread: Replacing embedded text with getline(cin, input); ?

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    90

    Replacing embedded text with getline(cin, input); ?

    Could someone show me what is the code sequence to accept user input at the keyboard. I know how to get the text. I need to know how to replace the line **account1.debit( 25.0 )** with the actual user input number that is in --- ** getline(cin, input)**

    The function in place works well for embedded data. I just want to use the number from the keyboard input and not embedded data.

    Thanks in advance


    Code:
    int main()
    {
    string input;
    
    cout << "Account1 balance is $50,00 << endl;
    cout << "Enter an amount to withdraw from Account 1: ";
    getline(cin, input);
    
    cout << "Attempting to debit $25.00 from account1." << endl;
    account1.debit( 25.0 );
    }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Ummm .... how about cin >> x ... cout << "debiting" << x << "from account 1"<< endl; ...
    account1.debit(x);

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Code:
    // same code as before....
    
    float  x;
    
    cout << "enter debit amount  :"
    cin >> x;
    
    cout << "debiting" << x << "from account1" << endl;
    account1.debit( x );
    Alternatively if you already have the value from getline(cin, input) ... just use account.debit(input);




    And it's very bad form to start a new thread with the same question...
    Last edited by CommonTater; 01-24-2011 at 09:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. text input from user
    By Gallard in forum C Programming
    Replies: 3
    Last Post: 09-17-2009, 05:31 PM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  3. Need some help with C program writing
    By The_PC_Gamer in forum C Programming
    Replies: 9
    Last Post: 02-12-2008, 09:12 PM
  4. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  5. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 11:28 PM