Reputation: 11
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;
}
Upvotes: 0
Views: 399
Reputation: 824
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?
Upvotes: 1
Reputation: 29468
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.
Upvotes: 0