Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,616 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 989 people online right now. Registration is fast and FREE... Join Now!




User Prompt and Input Problem

 
Reply to this topicStart new topic

User Prompt and Input Problem

hlabrams
post 29 Aug, 2006 - 05:06 AM
Post #1


D.I.C Head

**
Joined: 17 Aug, 2006
Posts: 66


My Contributions


When loading my table, I am asked "Do you want to enter another student?" When I select 1 for yes, the prompt for the data is like this: Last Name: First Name:
It should do this:
Last Name:
First Name:
This doesn't happen when I am entering data for the first student, just when I try to enter data for another student. Fixing it with a cin.get() has caused the first letter of the last name and first name to be cut off when the table is displayed. How else can I fix this??
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 29 Aug, 2006 - 05:37 AM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,176



Thanked 33 times

Dream Kudos: 25
My Contributions


For each post made, please post the relative section of the code. Members have no way to tell that this is an ongoing project, so the code will help them decipher the problem.
User is offlineProfile CardPM

Go to the top of the page

hlabrams
post 29 Aug, 2006 - 05:52 AM
Post #3


D.I.C Head

**
Joined: 17 Aug, 2006
Posts: 66


My Contributions


Here's the part of the code that's giving me trouble:
CODE

int Load_Student_Table(STUDENT_STRUCT student_table[], int num_students)
{
    int row=0;
    int response=1;
    
    
    cout << endl;
    cout << "Enter the table values as you are prompted:"
         << endl << endl;

    while(response==1)
    {
        
cout << endl << endl;
cout << "For row #" << row+1 << " enter:" << endl << endl;

cout << "Last Name: ";
cin.getline(student_table[row].last_name, 31);

cout << "First Name: ";
cin.getline(student_table[row].first_name, 31);

cout << "Social Security Number: ";
cin.getline(student_table[row].soc_sec_no, 10);

cout << "Phone Number: ";
cin.getline(student_table[row].ph_no, 11);

cout << "Quiz 1: ";
cin >> student_table[row].quiz_1;

cout << "Quiz 2: ";
cin >> student_table[row].quiz_2;

cout << "Quiz 3: ";
cin >> student_table[row].quiz_3;

cout << "Quiz 4: ";
cin >> student_table[row].quiz_4;

cout << "Quiz 5: ";
cin >> student_table[row].quiz_5;

cout << "Final Exam: ";
cin >> student_table[row].final_exam;

row++;
cout<<"Do you wish to enter another student? Enter 1 for yes or 0 for no: "<<endl;
cin>>response;
    }
    
return row;
}


This post has been edited by Dark_Nexus: 29 Aug, 2006 - 06:42 AM
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 29 Aug, 2006 - 06:32 AM
Post #4


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,905



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


Works fine for me when I assume a character array for the last_name and similar variable names.

What data types have you used for these variables?
User is offlineProfile CardPM

Go to the top of the page

hlabrams
post 29 Aug, 2006 - 06:45 AM
Post #5


D.I.C Head

**
Joined: 17 Aug, 2006
Posts: 66


My Contributions


QUOTE(born2c0de @ 29 Aug, 2006 - 07:32 AM) *

Works fine for me when I assume a character array for the last_name and similar variable names.

What data types have you used for these variables?



The first 4 are type char. The quizzes, final exam, and final grade are type int.
The quiz avg. is type double.
User is offlineProfile CardPM

Go to the top of the page

Jayman
post 29 Aug, 2006 - 09:47 AM
Post #6


Student of Life

Group Icon
Joined: 26 Dec, 2005
Posts: 6,839



Thanked 38 times

Dream Kudos: 500

Expert In: C#, VB.NET, Java

My Contributions


You could try clearing the buffer before taking your first input by using fflush(stdin). It will clear all input from the buffer for you.
User is offlineProfile CardPM

Go to the top of the page

help-linux
post 29 Aug, 2006 - 09:58 AM
Post #7


D.I.C Head

Group Icon
Joined: 12 Aug, 2006
Posts: 54



Thanked 1 times

Dream Kudos: 50
My Contributions


this should work:
CODE

int Load_Student_Table(STUDENT_STRUCT student_table[], int num_students)
{
    int row=0;
    int response=1;
    
    
    cout << endl;
    cout << "Enter the table values as you are prompted:"
         << endl << endl;

    while(response==1)
    {
        
cout << endl << endl;
cout << "For row #" << row+1 << " enter:" << endl << endl;

cout << endl << "Last Name: ";
cin.getline(student_table[row].last_name, 31);

cout << endl << "First Name: ";
cin.getline(student_table[row].first_name, 31);

cout << "Social Security Number: ";
cin.getline(student_table[row].soc_sec_no, 10);

cout << "Phone Number: ";
cin.getline(student_table[row].ph_no, 11);

cout << "Quiz 1: ";
cin >> student_table[row].quiz_1;

cout << "Quiz 2: ";
cin >> student_table[row].quiz_2;

cout << "Quiz 3: ";
cin >> student_table[row].quiz_3;

cout << "Quiz 4: ";
cin >> student_table[row].quiz_4;

cout << "Quiz 5: ";
cin >> student_table[row].quiz_5;

cout << "Final Exam: ";
cin >> student_table[row].final_exam;

row++;
cout<<"Do you wish to enter another student? Enter 1 for yes or 0 for no: "<<endl;
cin>>response;
    }
    
return row;
}


This post has been edited by help-linux: 29 Aug, 2006 - 09:59 AM
User is offlineProfile CardPM

Go to the top of the page

hlabrams
post 29 Aug, 2006 - 10:42 AM
Post #8


D.I.C Head

**
Joined: 17 Aug, 2006
Posts: 66


My Contributions


QUOTE(help-linux @ 29 Aug, 2006 - 10:58 AM) *

this should work:
CODE

int Load_Student_Table(STUDENT_STRUCT student_table[], int num_students)
{
    int row=0;
    int response=1;
    
    
    cout << endl;
    cout << "Enter the table values as you are prompted:"
         << endl << endl;

    while(response==1)
    {
        
cout << endl << endl;
cout << "For row #" << row+1 << " enter:" << endl << endl;

cout << endl << "Last Name: ";
cin.getline(student_table[row].last_name, 31);

cout << endl << "First Name: ";
cin.getline(student_table[row].first_name, 31);

cout << "Social Security Number: ";
cin.getline(student_table[row].soc_sec_no, 10);

cout << "Phone Number: ";
cin.getline(student_table[row].ph_no, 11);

cout << "Quiz 1: ";
cin >> student_table[row].quiz_1;

cout << "Quiz 2: ";
cin >> student_table[row].quiz_2;

cout << "Quiz 3: ";
cin >> student_table[row].quiz_3;

cout << "Quiz 4: ";
cin >> student_table[row].quiz_4;

cout << "Quiz 5: ";
cin >> student_table[row].quiz_5;

cout << "Final Exam: ";
cin >> student_table[row].final_exam;

row++;
cout<<"Do you wish to enter another student? Enter 1 for yes or 0 for no: "<<endl;
cin>>response;
    }
    
return row;
}



Thanks. I did that but now, it displays like this:

Last Name:
First Name: This is how I want it displayed, but it puts the cursor after First Name and doesn't allow me to enter the Last Name.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 03:05AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month