By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,511 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,511 IT Pros & Developers. It's quick & easy.

Logical Error. Not Returning

P: n/a
The problem starts during my while loop. It checks to see if they hit x
or X. If they did, then that means the user wants to exit. Then should
go on and hit the return statement. It just quits. When I hit x, it
pauses for a second then just goes to the next line on the cmd prompt.
My other returns work just fine though. I'm sure its just a stupid
logical error somewhere that I havn't caught. If anyone can point out
any tips that or whats wrong with it that would be great. Thanks again
to all!

int editBook(int a)
{

///////used to hold new values///
char xisbn[14];
char xtitle[51];
char xauthor[51];
char xpublisher[31];
char xdate[11];
int xqty;
float xwholeSale;
float xretail;
/////////////////////////////////

char change ='z';
char lookUp[51];
bool found = false;

system("cls");
cout << "\n\t\tEnter the title of the book you wish to edit ";
cin >> lookUp;
system("cls");

for(int index = 0; index < 20 && !found; index++)
{
// toupper
char up1[51], up2[51];
for(int position=0; position < 51; position++)
{
up1[position] = toupper(lookUp[position]);
up2[position] = toupper(bookTitle[index][position]);
}
if (strcmp(up1, up2) == 0)
{
found = true;
bookinfo(isbn[index], bookTitle[index], author[index],
publisher[index], dateAdded[index], qtyOnHand[index], wholesale[index],
retail[index]);
}
}

if(!found)
{
cout << "Book not in Inventory";
return 0;
}
cout <<"\n\nEnter the first letter of the category you would like to
edit or 'x' to exit: ";
cin >> change;

while (change != 'x' || change!='X')
{
if (change == 'I' || change =='i')
{ cin.ignore();
cout << "Enter the new ISBN number: ";
cin.getline(xisbn,14);
strcpy(isbn[index], xisbn);
cout << "The isbn is now " << isbn[index];
cout <<"\n\nEnter the first letter of the category you would like to
edit or 'x' to exit: ";
cin >> change;

}
if (change == 'T' || change =='t')
{
cin.ignore();
cout << "Enter the new Title: ";
cin.getline(xtitle,51);
strcpy(bookTitle[index], xtitle);
cout << "The title is now " << bookTitle[index];
cout <<"\n\nEnter the first letter of the category you would like to
edit or 'x' to exit: ";
cin >> change;
}
if (change == 'A' || change =='a')
{
cin.ignore();
cout << "Enter the new Author: ";
cin.getline(xauthor,51);
strcpy(author[index], xauthor);
cout << "The author is now " << author[index];
cout <<"\n\nEnter the first letter of the category you would like to
edit or 'x' to exit: ";
cin >> change;
}
if (change == 'P' || change =='p')
{
cin.ignore();
cout << "Enter the new Publisher: ";
cin.getline(xpublisher,31);
strcpy(publisher[index], xpublisher);
cout << "The publisher is now " << publisher[index];
cout <<"\n\nEnter the first letter of the category you would like to
edit or 'x' to exit: ";
cin >> change;
}
if (change == 'D' || change =='d')
{
cin.ignore();
cout << "Enter the new Date: ";
cin.getline(xdate,11);
strcpy(dateAdded[index], xdate);
cout << "The date is now " << dateAdded[index];
cout <<"\n\nEnter the first letter of the category you would like to
edit or 'x' to exit: ";
cin >> change;
}
if (change == 'Q' || change =='q')
{
cout << "Enter the new Quantity on Hand: ";
cin >> xqty;
qtyOnHand[index] = xqty;
cout << "The Quantity on Hand is now " << qtyOnHand[index];
cout <<"\n\nEnter the first letter of the category you would like to
edit or 'x' to exit: ";
cin >> change;
}
if (change == 'W' || change =='w')
{
cout << "Enter the new Whole Sale: ";
cin >> xwholeSale;
wholesale[index] = xwholeSale;
cout << "The Whole Sale is now " << wholesale[index];
cout <<"\n\nEnter the first letter of the category you would like to
edit or 'x' to exit: ";
cin >> change;
}
if (change == 'R' || change =='r')
{
cout << "Enter the new Retail: ";
cin >> xretail;
retail[index] = xretail;
cout << "The retail is now " << retail[index];
cout <<"\n\nEnter the first letter of the category you would like to
edit or 'x' to exit: ";
cin >> change;
}

}
return 0;
}

Oct 31 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"GRoll21" <mr*****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
The problem starts during my while loop. It checks to see if they hit x
or X. If they did, then that means the user wants to exit. Then should
go on and hit the return statement. It just quits. When I hit x, it
pauses for a second then just goes to the next line on the cmd prompt.
My other returns work just fine though. I'm sure its just a stupid
logical error somewhere that I havn't caught. If anyone can point out
any tips that or whats wrong with it that would be great. Thanks again
to all!
while (change != 'x' || change!='X')


while (change != 'x' && change != 'X')
-Mike
Oct 31 '05 #2

P: n/a
aww man. i really need to take a lil break. something so stuipd i
should of caught. thanks very much though for pointing it out!

- mike

Oct 31 '05 #3

P: n/a
"GRoll21" <mr*****@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
aww man. i really need to take a lil break. something so stuipd i
should of caught. thanks very much though for pointing it out!


It's been my experience that such 'dumb' mistakes
are often the result of trying to write too much
code at once.

Write your code in small increments, and TEST, TEST, TEST!!

(I was able to quickly diagnose the trouble by deleting
99% of that code you posted, replacing it with:

#include <iostream>
using namespace std;

int main()
{
char change(0);
bool condition(false);
cout << "Enter: ";
cin >> change;

while (condition = (change != 'x' || change!='X'))
{
cout << "inside loop, condition == " << condition << '\n';
}

cout << "loop done, condition == " << condition << '\n';
return 0;
}

The problem became immediately obvious.

-Mike
Oct 31 '05 #4

P: n/a

"GRoll21" <mr*****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
The problem starts during my while loop. It checks to see if they hit x
or X. If they did, then that means the user wants to exit. Then should
go on and hit the return statement. It just quits. When I hit x, it
pauses for a second then just goes to the next line on the cmd prompt.
My other returns work just fine though. I'm sure its just a stupid
logical error somewhere that I havn't caught. If anyone can point out
any tips that or whats wrong with it that would be great. Thanks again
to all!

int editBook(int a)
{

///////used to hold new values///
char xisbn[14];
char xtitle[51];
char xauthor[51];
char xpublisher[31];
char xdate[11];
int xqty;
float xwholeSale;
float xretail;
/////////////////////////////////

char change ='z';
char lookUp[51];
bool found = false;

system("cls");
cout << "\n\t\tEnter the title of the book you wish to edit ";
cin >> lookUp;
system("cls");

for(int index = 0; index < 20 && !found; index++)
{
// toupper
char up1[51], up2[51];
for(int position=0; position < 51; position++)
{
up1[position] = toupper(lookUp[position]);
up2[position] = toupper(bookTitle[index][position]);
}
if (strcmp(up1, up2) == 0)
{
found = true;
bookinfo(isbn[index], bookTitle[index], author[index],
publisher[index], dateAdded[index], qtyOnHand[index], wholesale[index],
retail[index]);
}
}

if(!found)
{
cout << "Book not in Inventory";
return 0;
}
cout <<"\n\nEnter the first letter of the category you would like to
edit or 'x' to exit: ";
cin >> change;

while (change != 'x' || change!='X')


This will always be true. You want to AND them, not OR them.

while (change != 'x' && change != 'X' )

same with the rest.
Nov 1 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.