Thread: Clearing Buffer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fallen AndyBomstad's Avatar
    Join Date
    Jan 2005
    Posts
    52

    New Problem

    ok im trying to write a program using 2 Char Arrays of about size 10, and i want the first to be a users first name and the 2nd to be their last

    once they enter both first and last i want it to desplay like this:

    BUCKET #0 = A
    BUCKET #1 = N
    BUCKET #2 = D
    BUCKET #3 = Y

    BUCKET #0 = B
    BUCKET #1 = O
    BUCKET #2 = M
    BUCKET #3 = S
    BUCKET #4 = T
    BUCKET #5 = A
    BUCKET #6 = D

    i do NOT want it to show up like this :

    BUCKET #0 = A
    BUCKET #1 = N
    BUCKET #2 = D
    BUCKET #3 = Y
    BUCKET #4 =
    BUCKET #5 =
    BUCKET #6 =
    BUCKET #7 =
    BUCKET #8 =
    BUCKET #9 =

    BUCKET #0 = B
    BUCKET #1 = O
    BUCKET #2 = M
    BUCKET #3 = S
    BUCKET #4 = T
    BUCKET #5 = A
    BUCKET #6 = D
    BUCKET #7 =
    BUCKET #8 =
    BUCKET #9 =


    the following code will display this :

    BUCKET #0 = A
    BUCKET #1 = N
    BUCKET #2 = D
    BUCKET #3 = Y
    BUCKET #4 =
    BUCKET #5 =
    BUCKET #6 =
    BUCKET #7 =
    BUCKET #8 =
    BUCKET #9 =
    press any key to continue....

    And Nothing more, it doesnt even show the last name....
    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
        char first[10];
        char last[10];
        int i = 0 ;
        cout<<"Please Enter Your First Name: ";
        cin>>first;
        cout<<"Please Enter Your Last Name: ";
        cin>>last;
        while(i <= 9)
        {
                
                cout<<endl<<"Bucket #"<<i<<" = "<<first[i]<<endl;
                i++;
        }
        while(i <= 9)
        {
                
                cout<<endl<<"Bucket #"<<i<<" = "<<last[i]<<endl;
                i++;              
        }
        system("pause");
    }
    and i know its somthing with the input buffer or checking to see if it found the EOF, but i dont know how to go about doing this
    Last edited by AndyBomstad; 04-27-2005 at 12:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proper method of clearing buffer
    By Oldman47 in forum C++ Programming
    Replies: 14
    Last Post: 04-23-2007, 07:14 PM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. Clearing input buffer after using getch()
    By milkydoo in forum C++ Programming
    Replies: 3
    Last Post: 07-21-2003, 11:04 PM
  4. text input buffer clearing
    By red_Marvin in forum C++ Programming
    Replies: 4
    Last Post: 03-20-2003, 03:17 PM
  5. Console Screen Buffer
    By GaPe in forum Windows Programming
    Replies: 0
    Last Post: 02-06-2003, 05:15 AM