-
Structures
Ok, heres my problem.
i have a structure here it is:
struct route
{
char cityCode1[3];
char cityCode2[3];
char cityCode3[3];
char cityCode4[3];
char cityCode5[3];
char cityCode6[3];
char cityCode7[3];
};
route truckRoute;
int index = 1;
now, i'm assigning values( 3 letter chars) to the variables.. i want to be able to increment the variable names # (ex. cityCode1 to cityCode2) when I do a cin>>, would this be accomplished by the following set of code? or Could someone help me to determine the correct procedure
cin >>cityCode
cityCode = truckRoute.citycode<<index
index++
Andrew Wilmut
-
Make an structure of arrays of arrays of chars...
Code:
#include <iostream>
const int NUM_CODES=7;
const int CODE_LENGTH=3;
struct route
{
char cityCode[NUM_CODES][CODE_LENGTH];
};
int main() {
route truckRoute;
for (int i =0; i < NUM_CODES; i++) {
std::cout << "Enter city code " << i + 1<< " for truck route: ";
std::cin >> truckRoute.cityCode[i];
}
return 0;
}
-
Damm you beat me
but I think you need to declare CODE_LENGTH as 4 to take into account the '\0'
mind you i don't do much c++.
-
Ok, but is what I was suggesting possible??
i'm not that far ahead in my c++ courses to do what u suggest...
Andrew Wilmut
-
i just need a way to be able to input the 3 letter codes in sequence
-
No, what you said is not possible.
cin >>cityCode
cityCode = truckRoute.citycode<<index
index++
cityCode, without being bound to the name of a route, has no meaning. Also, I have absolutely no clue what this means...
cityCode = truckRoute.citycode<<index