tags:

views:

295

answers:

2

Can Someone tell me what I am doing wrong I have tried my best with this program, please someone with a little more time on their hands so that they can take time to look at the program and Help! Thank you all for your time:)

#include <iostream>
#include <string>
#include <cctype>

using std::cout;
using std::cin;
using std::endl;

//function prototypes
void getItemNumber ();
void checkItemNumber (char *, int);

int main()
{
   //declare variables
   string Item = ""; 
   getItemNumber(); 
   checkItemNumber(item);


   //call function to get input

   //void getItemNumber ();
   //void checkItemNumber (item);
   cout << "Enter your 5-digit item #: ";
   cin >> item;

   while (item.length() != 5)
   {
       cout << "Invalid item #. Please enter a 5-digit item # ";
       getline(cin, item);
   }

   if (item.length() == 5)
   {
       if ('B' == toupper(item[2])) 
           cout << "Your color is blue" << endl;
       else if ('G' == toupper(item[2])) 
           cout << "Your color is green" << endl;
       else if ('R' == toupper(item[2]))
           cout << "Your color is red" << endl;
       else if ('W' == toupper(item[2]))
           cout << "Your color is white" << endl;
   }
   else
       cout<< "Invalid name no matching color..."; 
       // if code is not from any of the above.

   system("pause");

   return 0;
}
A: 

you need #include <ctype> for tolower.

the functions getItemNumber and checkItemNumber are not defined by any C standard, you should ask the one from which you got the code where getItemNumber and checkItemNumber are defined.

codymanix
This sounds like a homework assignment "Modify the following code so that it uses separate functions getItemNumber and checkItemNumber". Presumably defining the functions is part of the assignment.
Larry Lustig
The OP has included cctype, which provides C++ wrappers for ctype.h C functions. See this: http://www.cplusplus.com/reference/clibrary/cctype/
s1n
he didn't include it, is was edited into the question later..
codymanix
Okay, but it's still not <ctype>.
s1n
@Larry, very vague, this is my first time coding this program so I just need a clear example, that would be a great help like how exactly should I set it up, just use an example so that you do not feel as you are doing my homework for me. Thanks:)
Rosemary
@codymanix, I am sorry I am little confused by your comment these two are C++ functions ??? Thanks!
Rosemary
+1  A: 

Not sure I get the point of the question, but there is a definite bug (in my opinion) in the code as it appears above.

Ask yourself under what conditions will the error message get printed out? In other words, what "if" does the "else" belong to?

Tony van der Peet