Hello all,

I am enrolled in an intro to C++ class, and I need some help on our final program. Any suggestions are greatly appreciated, as I am quite new to this please don't criticize.

Our program requirements require us to receive a command (I.E. delete) input as an array of characters, null-byte terminated. This input must be converted to all caps because the function should accept text of any case.

The function must then return the matching pre-defined enum command value.

We are not allowed to use strings, and should instead use strlen, strcpy, and strcmp.

Any ideas? Here is the code of what I've got so far. This is only the portion I am having trouble with.

#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;

                   SORT_BY_TOTAL_WEIGHT, QUIT };
CommandType ReadAndReturnCommandType( );
// Global Constants
const int MAX_DESC_NAME_LEN = 30;
const int MAX_RECIPEINT_LEN = 30;
const int MAX_COMMAND_LEN = 30;
const int MAX_SHIPMENTS = 20;
const int MAX_ITEMS_PER_SHIPMENT = 20;
const int LARGER_THAN_NINE = 10;
const int NOT_FOUND = -1;

// Custom Alias Declarations
typedef char DescriptionType[MAX_DESC_NAME_LEN + 1];
typedef char RecipientType[MAX_RECIPEINT_LEN + 1];
typedef char CommandCStrngType[MAX_COMMAND_LEN + 1];

int main( )
   CommandType command = ReadAndReturnCommandType();
   while ( command != QUIT )
      cout << "Processing command ";
        PrintCommandType( command );
        cout << endl;
        HandleCommand ( shipList, command );
        cout << endl;
        command = ReadAndReturnCommandType();
   return 0;

//Purpose: Reads a command string and returns
//         the appropriate CommandType.
//         The default return type is QUIT.
// Params: ( none )
CommandType ReadAndReturnCommandType()
   CommandCStrngType command;
   cin >> command;
   for( int i = 0; i < strlen(command); i++ )
      command[i] = toupper( command[i] );
   switch( command )          // <-------Here is where the error occurs.
      case "ADD":
         return ADD;
      case "DELETE":
         return DELETE;
// ......
      case default:
         return QUIT;

As far as I know you can only 'switch' on int types. CommandCStrngType is definitely not convertible to an int! You should just replace your switch statement with a big if/else if/else.

This article has been dead for over six months. Start a new discussion instead.