473,499 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Logical Error. Not Returning

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
4 1630
"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
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
"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3995
by: muser | last post by:
Can anyone run this program through their compiler or if they can see a logical error please point it out. I have my tutor working on it at the moment but I would rather a less ambigious response...
6
44076
by: Hari Om | last post by:
Here are the details of my error log files: I execute the command and get following message at console: ---------------------------------------------------------------------- ../sqlldr...
80
35019
by: Christopher Benson-Manica | last post by:
Of course one can get the effect with appropriate use of existing operators, but a ^^ operator would make for nice symmetry (as well as useful to me in something I'm working on). Am I the only one...
6
4207
by: moosdau | last post by:
it's likely that the compiler could only promise returning a non-zero value in my impression, but it did return 1 every time, like the code below: int a=3,b=8; printf("%d\n",a<b); will it ...
2
4099
by: ThunderMusic | last post by:
Hi, I have a value that contains flags that I must get using a bitmask. I tryied with the && operator, but the compiler outputs this error : Operator '&&' cannot be applied to operands of type...
0
1175
by: Roald | last post by:
I am working on an application that needs to implement logical deletes instead of removing the records permanently. The logical delete works by setting 3 fields (deleted flag, date and user). I...
14
36833
by: blueboy | last post by:
Hi, I am planning to automate a nighty restore of a DB on another server can someone point me in the right direction with the SQL script to modify the logical file names to the correct path and...
11
4657
by: Dominic Vella | last post by:
I am using MS-Access2000. I can't seem to set the default values for Logical type fields. I start with Dim dbsTmp As Object ' I think it's DAO.Database Set dbsTmp =...
7
3537
by: raylopez99 | last post by:
I have a logical drawing space much bigger than the viewport (the screen) and I'd like to center the viewport (the screen) to be at the center of the logical drawing space. After following the...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.