Integer arrays of Character arrays...help!

ok so...I need to make a program where the user enters a number between 0 and 10. Depending on what number they put in, is how many colleges it will display. I need to store the names, locations, and mascots of 10 different colleges as elements of an integer array so I can call certain numbers of lines depending on what the user inputs, however each element of that array will be another array of characters (the college stuff)...so yeah...I have no idea how to do this.

I know how to make an integer array, and allow the user to input a number and display all of the array values up to that point, but I just cant figure out the part of making each element of an integer array a string of characters....

Ex.

Number of colleges : (user inputs 2)

Output :

Nebraska, Lincoln, Cornhusker

Kansas, wherever, Jayhawks

---------------

Number of colleges : (user inputs 4)

Output :

Nebraska, Lincoln, Cornhusker

Kansas, wherever, Jayhawks

whatever, whatever, whatever

whatever, whatever, whatever

... You get the idea...I just suck with arrays...help me and I will love you long time.

#268040

it sounds like youre getting confused....if you need 10 colleges, you will have an array that will be indexed from 0-9 for the 10 spots. you could just do this...i'll do it in java, i dont know what you're using but you should be able to decipher it

String[] colleges = new String[10];



// assign all the info...like the following

colleges[0] = "Nebraska, Lincoln, Cornhuskers";



// get the input number from the user, i'll call it n



for(int i=0; i < n; i++)

{

System.out.println(colleges[i]);

}

#270930

no...I'm not confused, but I think you are.

I need to assign a string of characters to each value of an integer array, so I can call them using a loop.

for example colleges[0] = "nebraska, lincoln, cornhuskers"

colleges[1] = "whatever, whatever else, whatever else"

colleges[2] = "blah, blah, blah"

than using a for loop I can allow the user to input how many colleges the user wants to display

for(x=0;x

cout << colleges[x];

}

any ideas?

#271101

If thats possible I dont know, but a messy and ****ish alternative would be to echo one college name when x is 0, another when X is 1 using an IF condition, it wouldnt be THAT messy and if you want to get it done quick just do that, because as far as I know a character string is an array itself containing seperate letters Oo

#271116

Spoonraker, im guessing C++, right? - start off by saying what coding language. Moonrules initiated an array of strings, that can be done in java.

This is how you initialize an array of strings in C++

string names[array_Size];

#271124

spoonraker; You can't assign characters to an integer array. An integer array stores integers.

If you're coding in C++ (which I think it's safe to assume since you're using cout), you can make a string array the way Seph said:

string colleges[10];

Then assign the names of the colleges like:

colleges[0] = "College 1";

colleges[1] = "College 2";

and so on. That way, you have a string array.

#271136

so like i said...my way was java so it would be different but you can do the EXACT same thing using C++ syntax...

#271234

here's my code! woo hoo

#include

#include

using namespace std;

int main() {

string colleges[9];

int x;

int input;

colleges[0]="Nebraska tt Lincoln tt NE tt Huskersn";

colleges[1]="Iowa State tt Ames tt IA tt Cyclonesn";

colleges[2]="Alabama tt Birmingham tt AL tt Crimson Tiden";

colleges[3]="Kentucky tt Lexington tt KY tt Wildcatsn";

colleges[4]="Texas Tech tt Lubbock tt TX tt Red Raidersn";

colleges[5]="Kansas tt Lawrence tt KS tt Jayhawksn";

colleges[6]="Western Kentucky tt Bowling Green tt KY tt Hilltoppersn";

colleges[7]="UCLA tt Las Angeles tt CA tt Bruinsn";

colleges[8]="Wisconsin tt Madison tt WI tt Badgersn";

colleges[9]="Stanford tt Stanford tt CA tt Cardinalsn";

cout << "How many colleges do you want to view?";

cin >> input;

for (x=0;x

cout << colleges[x];

}

return 0;

}

It still doesnt work...its gives me some kind of BUS error...yippee

#271346

SHUT UP I KNOW....

string colleges[10];

it works now....

#271348

#include <iostream.h>

#include <string.h>

should be

#include <iostream>

#include <string>

Without the .h suffix on the standard-headers ;)

#271349