View Single Post
Old 02-25-2006, 02:53 PM   #1 (permalink)
Java2
Registered User
 
Join Date: Oct 2005
Posts: 19
Java2 is on a distinguished road
storing values in an empty array

I enter 9 values into an empty array (no itnitialized data)
and try to output them at the end but it doesn't. I have managed to find that the data is just not geting stored there.

this is the code
Code:
#include <string>
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

// +++++++++++++++++++++++variables++++++++++++++++++++++++++
char* letterArray[9] = {};
int i;
char* vowel;
char* consonant;
int ln;
string choice;
// ++++++++++++++++++++++Functions++++++++++++++++++++++++++++ 

// +++++Vowel function+++++
char* randomVowel()
{
//vowel Array
char* vowelArray[5] = {"A", "E", "I", "O", "U"};

//Random Generater
srand ((unsigned)time(0));
int vn;
vn = (rand()%5);

//assign to the array

//return
return vowelArray[vn];
}

// +++++Consonant function++++
char* randomConsonant()
{
//Consonant Array
char* consonantArray[21] = {"B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z"};

//Random Generater
srand ((unsigned)time(0));
int vn;
vn = (rand()%20);

//return
return consonantArray[vn];
}

// Main Program 
int main()
{

//Ask the letter type and loop 9 times

for (i = 0; i < 9; )
{
cout << "Would you like a Vowel or a consonant? <V/C>\n"; 
cin >> choice;
if (choice == "v" || choice == "C")
{
           //get a random vowel
           cout << randomVowel() << "\n";
           vowel = randomVowel();
           vowel = letterArray[i];
           i++;
}
else if (choice == "c" || choice == "C")
{
     //get a random consonant
     cout << randomConsonant() << "\n";
     consonant = randomConsonant();
     consonant = letterArray[i];
     i++;
}
else
{
    cout << "That is not a valid request!\n";
}
}

// ouputting the letter array
for(ln = 0; ln < 9; ln++)
{
cout << "\n" << letterArray[ln];
}


return 0;
}
if i haven't explained this properly or are just wandering what the hell i am doing please don't hesitate to ask.

many Thanks
Java2 is offline   Reply With Quote