| | |
problems with type q to quit
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2009
Posts: 12
Reputation:
Solved Threads: 0
This subroutine is very basic, however I am struggling.
When the user types q (or Q) into the input when asked for the vendor name, the program should return false... However, this function is always returning true.
MY if statement is clearly not working:
(*vendorName != 'q' || *vendorName != 'Q')
Anyone know why? Thanks.. Here's the code:
When the user types q (or Q) into the input when asked for the vendor name, the program should return false... However, this function is always returning true.
MY if statement is clearly not working:
(*vendorName != 'q' || *vendorName != 'Q')
Anyone know why? Thanks.. Here's the code:
C++ Syntax (Toggle Plain Text)
bool getVendor(data & adata) { char vendorName[MAX_LEN]; char phoneNum[MAX_LEN]; char productType[MAX_LEN]; int eventNum; char events[MAX_LEN]; cout << "\nPlease enter information about the winery: " << endl; getString("\tVendor name(type q to quit): ", vendorName); if(*vendorName != 'q' || *vendorName != 'Q') { getString("\tPhone number: ", phoneNum); getString("\tType of product: ", productType); eventNum = getInt("\tThe amount of events: "); getString("\tName(s) of events: ", events); adata.setVendorName(vendorName); adata.setPhoneNum(phoneNum); adata.setProductType(productType); adata.setEventNum(eventNum); adata.setEvents(events); return true; } return false; }
•
•
Join Date: Apr 2008
Posts: 129
Reputation:
Solved Threads: 22
•
•
•
•
This subroutine is very basic, however I am struggling.
When the user types q (or Q) into the input when asked for the vendor name, the program should return false... However, this function is always returning true.
MY if statement is clearly not working:
(*vendorName != 'q' || *vendorName != 'Q')
Anyone know why? Thanks.. Here's the code:
C++ Syntax (Toggle Plain Text)
bool getVendor(data & adata) { char vendorName[MAX_LEN]; char phoneNum[MAX_LEN]; char productType[MAX_LEN]; int eventNum; char events[MAX_LEN]; cout << "\nPlease enter information about the winery: " << endl; getString("\tVendor name(type q to quit): ", vendorName); if(*vendorName != 'q' || *vendorName != 'Q') { getString("\tPhone number: ", phoneNum); getString("\tType of product: ", productType); eventNum = getInt("\tThe amount of events: "); getString("\tName(s) of events: ", events); adata.setVendorName(vendorName); adata.setPhoneNum(phoneNum); adata.setProductType(productType); adata.setEventNum(eventNum); adata.setEvents(events); return true; } return false; }
cpp Syntax (Toggle Plain Text)
*vendorName != 'q' || *vendorName != 'Q'
cpp Syntax (Toggle Plain Text)
vendorName[0] != 'q' && vendorName[0] != 'Q'
Last edited by ivailosp; Mar 11th, 2009 at 5:42 am.
•
•
Join Date: Mar 2009
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
change
tocpp Syntax (Toggle Plain Text)
*vendorName != 'q' || *vendorName != 'Q'
cpp Syntax (Toggle Plain Text)
vendorName[0] != 'q' && vendorName[0] != 'Q'
But that also brought about another problem.
Now if I type in any word that begins with q or Q, it returns false.
Is there away to avoid this? Because I only want the letters q and Q to return false. Not words that begin with q or Q.
Last edited by hansel13; Mar 11th, 2009 at 5:47 am.
•
•
•
•
Now if I type in any word that begins with q or Q, it returns false.
Is there away to avoid this? Because I only want the letters q and Q to return false. Not words that begin with q or Q.
Try something like this:
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main(void) { char input[51]; cout << "Type something: "; cin.getline(input, 50); cout << endl; if(!strcmp(input, "q") || !strcmp(input, "Q")) { cout << "A \"q/Q\" was detected !!!" << endl; } else { cout << "You typed: " << input << endl; } cin.get(); return 0; }
•
•
Join Date: Mar 2009
Posts: 12
Reputation:
Solved Threads: 0
I used the strcmp() function, but now the subroutine never runs true. The if statement doesn't seem to be effective. I tried doing the following:
if(!strcmp(*vendorName, "q") || !strcmp(*vendorName, "Q"))
if(!strcmp(vendorName[0], "q") || !strcmp(vendorName[0], "Q"))
but then I got syntax errors.
Not sure what's wrong with time..
if(!strcmp(*vendorName, "q") || !strcmp(*vendorName, "Q"))
if(!strcmp(vendorName[0], "q") || !strcmp(vendorName[0], "Q"))
but then I got syntax errors.
Not sure what's wrong with time..
C++ Syntax (Toggle Plain Text)
bool getVendor(data & adata) { char vendorName[MAX_LEN]; char phoneNum[MAX_LEN]; char productType[MAX_LEN]; int eventNum; char events[MAX_LEN]; cout << "\nPlease enter information about the winery: " << endl; getString("\tVendor name(type q to quit): ", vendorName); if(!strcmp(vendorName, "q") || !strcmp(vendorName, "Q")) { getString("\tPhone number: ", phoneNum); getString("\tType of product: ", productType); eventNum = getInt("\tThe amount of events: "); getString("\tName(s) of events: ", events); adata.setVendorName(vendorName); adata.setPhoneNum(phoneNum); adata.setProductType(productType); adata.setEventNum(eventNum); adata.setEvents(events); return true; } return false; }
C++ Syntax (Toggle Plain Text)
void getString(char * prompt, char * input) { cout << prompt; cin.get(input, MAX_LEN, '\n'); cin.ignore(100, '\n'); }
Last edited by hansel13; Mar 11th, 2009 at 7:07 pm.
![]() |
Similar Threads
- random number display the same (C#)
- Virus-Mallware problems (Viruses, Spyware and other Nasties)
- Parallel Array Help (C++)
- Problems with Switch (C++)
- struct array and enum problems (C++)
- Array troubles? (C++)
- Need help displaying when user enters negative number? (C++)
- Problems with displaying total payroll and allowing user to quit by entering a neg. (C++)
- hvving problems displaying after user inters negative number? (C++)
Other Threads in the C++ Forum
- Previous Thread: problem in text files
- Next Thread: Visual Studio 2005 acting weird
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






