Hi;
Trying to input something that has more then one character.
This is the line I'm trying to input.
Bill Smith
9763 N. Adrian Hwy //This second line is where I'm at
Ann Arbor Mi,48719
517-260-9871
The first name comes in fine I think, The last good too I think. Then my program doesn't wait for me to enter the street address.
What do you think is wrong here?
//Option A function
int optionA(ifstream &fin, infoType tele[], int& size)
{
cout << "You have selected option A. " << endl;
cout << "Please enter the first name " << endl;
for(int i = 0; i < 1; i++)
{
cin >> tele[i].fname;
}
cout << "Please enter the last name. " << endl;
for(int i= 0; i < 1; i++)
{
cin >> tele[i].lname;
}
cout << "Please enter the street address. " << endl;
for(int i = 0; i < 1; i++)
{
getline( cin,tele[i].streetAdd);
}
return size;
}
//Option A function
int optionA(ifstream &fin, infoType tele[], int& size)
{
cout << "You have selected option A " << endl;
cout << endl;
cout << "Please enter the first name. " << endl;
for(int i = 0; i < 1; i++)
{
cin >> tele[i].fname;
}
cout << "Please enter the last name. " << endl;
for(int i= 0; i < 1; i++)
{
cin >> tele[i].lname;
}
cout << "Please enter the street address. " << endl;
cin.get();
for(int i = 0; i < 1; i++)
{
getline(cin,tele[i].streetAdd, '\n');
}
return size;
}
If you notice I added cin.get();
This happened to me yesterday.
So, I have a question. Why is the occuring all of a sudden. I don't remember this happening in my other programs.
I read that cin leaves a space in the buffer stream ( I don't know the technical lingo), There is a space there. After the user hits enter. If that is true why does this not occur after my first input?Why ist his happening? Is this poor programming on my part or is this just the way it is.
Thanks
It's your development area which is integrated with a linker and compiler, say, for instance.
Arrays work well with loops which have INT pointers to an element within that array
int i_arry_pntr = 17;
int i_my_val =0;
int my_array [ ];
i_my_val = my_array [ i_arry_pntr ] // same as pointing to the last element in array named : my_array
or
for ( i_arry_pntr, i_arry_pntr < 17, i_arry_pntr ++ )
i_my_val = my_array [ i_arry_pntr ]
printf( "This val:%d", i_my_val ); // display all 17 values during the loop
In your case (above) you loop from -0- to - less than 1-
Which is why I suggest that you discard the loop altogether, as it is not doing any good as it stands now.
Try STEPPING through your code with your DEBUGGER and you will see what the code is doing and where it is doing it, and you will also see what the values of your variables are.
How do I do trace mode? You mean just the error messages the compiler gives?
I have another question maybe someone would know. I'm working on a function to delete and entry from a phone directory. I will post the part of the code it is easier then typing.
infoType tele[SIZE]; I know this is a constant size I use a different size later in the program for the array that isn't const. With that said my question is if I locate the number to be deleted from the directory. Based on user input then how can I delete that entry from the array I have.
Just that part of the array. Also should I be concerned with an empty spot in my array at all? This I'm unsure.
How you debug your program using the debugging tools depends on your compiler. You can find help on this subject on the internet.
if you don't wish to use the debugger, or if your compile doesn't have a good one or none at all, you can always set flags in your code. As your code is executed, your flags will show what line you're on and what you values are at that point.
- - - -
To delete an element from an array, I usually create a second array and move everything - except that one element - into the new array.
OK whats wrong with this search section of code? It does everything up to the while loop. Then just waits there. Something is up. I just want to go through the array and find the number.
Thanks
//Option D function
void optionD( ifstream &fin, infoType tele[], int& size)
{
int i = 0;
string dPhone;
bool found = false;
cout << "You have selected option D " << endl;
cout << "Please enter the phone number of the record to be deleted." << endl;
cin >> dPhone;
cout << size;
while( i < size && !found )
{
if( tele[i++].phone == dPhone )
{
found = true;
}
}
if(found == true)
cout << tele[i].phone << endl;
}