Hey all!
Ok so here's my problem:
The function that I am writing accepts 2 user inputs, one char and then one int. (one int one char assignment instructions)
However, I want to allow the user the ability to enter them in either order (1 char 2 int or 1 int 2 char ).
I have code that does allow me to accept both inputs in either order. So where's my problem?
My problem is the inputs the user is entering coincide to a location in a multidimensional array. I think there's an issue with the line of code that I set an int to a char (You all probably are lost, look for the stars in my code, this is where I think my problems are happening).
Maybe my problem is in the way I am accepting both inputs, but I can't think of another way. Any suggestions anyone might have for me would be greatly appreciated!!!!!
CODE
#include <iostream>
#include <cctype>
#include <iomanip>
using namespace std;
int main ()
{
int grid[5][5] =
{
{ 35, 0, 90, 50, 75},
{ 55, 10, 0, 0, 20 },
{ 0, 85, 40, 95, 60 },
{ 15, 0, 65, 5, 100 },
{ 70, 45, 25, 80, 30 }
};
char gridLocLetter;
int gridLocNumber;
cout << "Enter a grid location (such as B2, or 2b)";
cin >> gridLocLetter;
if( isalpha(gridLocLetter) != 0 )
{
cin >> gridLocNumber;
}
else if (isdigit(gridLocLetter) != 0)
************************************************
* { gridLocNumber = gridLocLetter; *
************************************************
cin >> gridLocLetter;
}
cout <<"GLL: " << gridLocLetter << " GLN: " << gridLocNumber << "\n";
cout << "Grid location: " << gridLocLetter << gridLocNumber << "\n";
int X;
if (gridLocLetter == 'A'|| gridLocLetter == 'a')
X = 0;
else if (gridLocLetter == 'B'|| gridLocLetter == 'b')
X = 1;
else if (gridLocLetter == 'C'|| gridLocLetter == 'c')
X = 2;
else if (gridLocLetter == 'D'|| gridLocLetter == 'd')
X = 3;
else if (gridLocLetter == 'E'|| gridLocLetter == 'e')
X = 4;
else
cout <<"Input error: letter range is A-E, number range is 1-5.\n";
cout << "X is: "<< X;
cout << grid[X][gridLocNumber-1] <<" ";
cout << "\n";
cout << "Item " << gridLocLetter << gridLocNumber << " costs " << "2" << " cents.\n"
system("PAUSE");
return 0;
}