[Dev-C++] OK, here's another stupid question....................
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Dany P. W. <da...@qu...> - 2003-01-28 03:54:14
|
They always say "There are no such thing as stupid questions, just
plenty of inquisitive idiots" but here it goes........
I'm still a complete beginner in C++ and programming in general. I've
written yet another silly little code to get used to the syntax and
arrays. I was going to use parallel arrays but so far have only tried to
use a single array. Something is causing me problems. The "while" loop
ignored the first "index" value of 0 and jumped to the second value of 1
before executing the commands within that loop. I've tried using a "for"
loop with no success either.
Can someone try this out and tell me what I've missed? Much
appreciated...........
============================================
#include <iostream>
#include <string>
#define TAB '\t'
main()
{
using namespace std;
//Define how many planets there are
int MAX;
cout << "Enter the number of planets: ";
cin >> MAX;
//Define max length of planet names
int LENGTH;
cout << "Enter max length of planet names: ";
cin >> LENGTH;
cout <<"There will be " << MAX << " planets" <<endl;
cout << "Each will be " << LENGTH << " chars long" <<endl;
LENGTH = LENGTH + 1;
//Define the 2 arrays, planet names and distances
char name[LENGTH];
char planet[MAX][LENGTH];
int distance[MAX];
int DIST;
int index = 0;
while (index < MAX)
{
cout << index << endl; //I put this in here to show that it
skipped the value 0
cin.getline(name,LENGTH);
strcpy(planet[index],name);
index++;
}
index = 0;
for (index = 0; index < MAX; index++)
{
cout << endl << planet[index] << endl;
}
system("PAUSE");
return(0);
}
============================================
--
This mail is a natural product. The slight variations in
spelling and grammar enhance its individual character and
beauty and in no way are to be considered flaws or defects.
|