When I put my code through different inputs, one form of input results in a problem. when I enter:
updatename 123456789 10 f9
the expected output is
"Error: 10 is out of the range 0-4"
whereas I got
"Error: argument is not a number"
i tried moving the error detection around and it wouldn't work. Seem like a simple problem but I can find the solution for it :S - int main()
-
{
-
char a[maxLength]; //command
-
char l[maxLength]; //last name
-
char f[maxLength]; //first name
-
int b;
-
int idx, mark;
-
-
// cin >> a >> b;
-
-
while (! cin.eof()) {
-
cin >> a;
-
if(cin.fail()) // checks for non-integer inputs
-
{
-
cout << "Error: Argument is not a number." << endl;
-
cin.clear(); // lowers error flag
-
cin.ignore(50, '\n'); // ignores rest of string
-
}
-
-
else {
-
for (char * c = a; *c != '\0'; c++)
-
*c = tolower(*c); // Scan through the entire string; change the input
-
// into lower case.
-
-
// See which of the commands was entered
-
-
-
if (!strcmp (a, "new")) { //checks for the command "new" in the string
-
-
if(cin >> b){
-
-
if(b <= 999999999){
-
cout<< "New: ";
-
cout.fill('0');
-
cout<< setw(9) << dec << b <<endl;
-
}
-
else{
-
cout<<"Error: "<< b <<" is too large.\n";}
-
}
-
}else if (!strcmp (a, "locate")) { //checks for the command "locate" in the string
-
if(cin >> b){
-
-
-
if(b <= 999999999){
-
cout<< "Locate: ";
-
cout.fill('0');
-
cout<< setw(9) << dec << b <<endl;
-
}
-
else{
-
cout<<"Error: "<< b <<" is too large.\n";
-
}
-
}
-
}else if (!strcmp (a, "updatename")) //checks for the command "updatename" in the string
-
{
-
if(cin >> b >> l >> f){
-
if(b <= 999999999){
-
cout<< "Updatename ";
-
cout.fill('0');
-
cout<< setw(9) << dec << b << "";
-
cout<<" "<< f << " "<< l <<endl;
-
}
-
else{
-
cout<<"Error: "<< b <<" is too large.\n";
-
}
-
}
-
}else if (!strcmp (a, "updatemark")) { //checks for the command "updatemark" in the string
-
-
if(cin >> b >> idx >> mark){
-
if(idx < 0 || idx > 4){
-
-
cout<<"Error:"<< idx <<" is out of the range 0-4.\n";
-
cin.clear();
-
cin.ignore(50, '\n');
-
}else if(mark < 0 || mark > 100){
-
cout<<"Error:"<< mark <<" is out of the range 0-100.\n";
-
-
}
-
if(b <= 999999999){
-
cout<< "Updatemark ";
-
cout.fill('0');
-
cout<< setw(9) << dec << b << "";
-
cout<<" "<< idx << " "<< mark <<endl;
-
}
-
else{
-
cout<<"Error: "<< b <<" is too large.\n";
-
}
-
-
}
-
-
-
-
}else if (!strcmp (a, "delete")) { //checks for the command "delete" in the string
-
if(cin >> b){
-
-
-
if(b <= 999999999){
-
cout<< "Delete: ";
-
cout.fill('0');
-
cout<< setw(9) << dec << b <<endl;
-
}
-
else{
-
cout<<"Error: "<< b <<" is too large.\n";
-
}
-
}
-
}else if (!strcmp (a, "printall")) { //checks for the command "printall" in the string
-
-
cout<< "Printall\n";
-
-
}else if (!strcmp (a, "deleteall")) { //checks for the command "delete" in the string
-
cout<< "Deleteall\n";
-
}else {
-
cin.ignore(1000,'\n');
-
cout<< "Error: Unknown Command\n";
-
}
-
-
}
-
-
}
-
-
return (0);}
2 1783 sicarie 4,677
Recognized Expert Moderator Specialist
When I put my code through different inputs, one form of input results in a problem. when I enter:
updatename 123456789 10 f9
the expected output is
"Error: 10 is out of the range 0-4"
whereas I got
"Error: argument is not a number"
i tried moving the error detection around and it wouldn't work. Seem like a simple problem but I can find the solution for it :S
Did you try putting cout statements after lines of execution, and find out where it will and won't get to in the program?
I used Visual Studio's debug feature to walk through the code line by line.
when I input
"updatemark 123456789 10 f9"
after cin >> a; it will strcmp to updatemark and then cin >> b >> idx >> mark;
then it will jump back to cin >> a; and produce "the arguement is not a number" because the value of a was alter to a unknown digit.
I can't seem to get this work no matter how i tried rearranging the code.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Cherrish Vaidiyan |
last post by:
sir,
The following are the steps that i followed in setting up standby
database on Red hat Linux 9. i am using Oracle 9i.
i have followed the steps in this site :
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96653/create_ps.htm#66206
Still i give the steps i followed.
Preparing the Primary Database for Standby Database Creation
|
by: andy johnson |
last post by:
I made the mistake of "upgrading" to IE6.0 on my windoze 98 laptop. I
really wish bill gates would die in a horribly painful accident.
Anyway, after much grief, I downloaded Opera and saw true religion.
The good in this is I discovered my web site http://www.oawater.com
has a slide show on the main page that is broke in Opera 7.11. I get
this error message. Can anyone give me some direction?
Event thread: onload
Error:
|
by: news.onetel.net.uk |
last post by:
I and my friend Karl have spent literally all day trying to find out what is
causing my error but we are zapped of any further functionality :)
I have a form that adds news records. You select 'City' then you select
'Business Category' - now when you select 'Business Category' the next
drop-down menu (business sub category) should populate with 'Business
Sub-categories' related to the 'Business Category' but once 'Business
Category' is...
|
by: debugger |
last post by:
hello,
Question, on page load, I populate an existing drop down with
createElement and appendChild. It works fine so far. BUT I want to
automatically select some option from this populated drop down. So i
have this statement:
document.getElementById("dropdown").options.selected=true;
And it gives me an error.
|
by: Frank van Vugt |
last post by:
Hi,
If during a transaction a number of deferred triggers are fired, what will be
their execution order upon the commit?
Will they be executed in order of firing or alfabetically or something
entirely different? The docs only mention regular triggers being executed
alfabetically.
| |
by: jeffc226 |
last post by:
I'm interested in an idiom for handling errors in functions without
using traditional nested ifs, because I think that can be very awkward
and difficult to maintain, when the number of error checks gets about
3 or so. It also gets very awkward in nested loops, where you want to
check for normal loop processing in the loop condition, not errors.
Yes, you could put some generic exit flag in the loop condition, but
when you're simply done if...
|
by: JohnQ |
last post by:
(The thread "Error Handling Idioms" prompted this post. I meant to post it
at the top level, but it got posted as a reply. So here it is again!)
An attempt at common defintions:
fault: the cause of error.
error: a detected fault.
error handling: planned processing (perhaps via formal mechanisms) that
occurs upon fault detection.
error correction: returning a program (or system) back to an error-free
|
by: harshadanarvekar |
last post by:
Hi Everyone,
Here is a part of javascript code that works well in FF2 but shows
above error in IE6 and error "missing name after . operator" in NS8
function PopUp(idf,stepX,stepY,speed){
|
by: origami.takarana |
last post by:
Intrusion Detection Strategies
-----------------------------------
Until now, we’ve primarily discussed monitoring in how it relates to
intrusion detection, but there’s more to an overall intrusion
detection installation than monitoring alone. Monitoring can help you
spot problems in your network, as well as identify performance
problems, but watching every second of traffic that passes through
your network, manually searching for...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |