mwanafunzi
April 1st, 2006, 11:19 PM
sup ubuntu,
I am having some problems with arrays. I want to enter a value into an array of index 5. The first problem i was having was that I was only able to enter one value then the program exits. after g++'ing the file, i get no errors, but when i ./a.out nothing happens (i.e. i get back onto the command line; almost as though i never called the program at all)
any ideas.
the difference between the first code that I had and this one is that I did not have
double amount = 0.0;
and I had
cin >> largest[counter];
Here is my code
#include <iostream>
using namespace std;
int main()
{
double largest[5], amount = 0.0;
int counter;
for(counter = 0; counter < largest[5]; counter++)
{
//counter++;
cout <<"enter value " << counter + 1 << ": ";
cin >> amount;
largest[counter] = amount;
}
return 0;
}
I am having some problems with arrays. I want to enter a value into an array of index 5. The first problem i was having was that I was only able to enter one value then the program exits. after g++'ing the file, i get no errors, but when i ./a.out nothing happens (i.e. i get back onto the command line; almost as though i never called the program at all)
any ideas.
the difference between the first code that I had and this one is that I did not have
double amount = 0.0;
and I had
cin >> largest[counter];
Here is my code
#include <iostream>
using namespace std;
int main()
{
double largest[5], amount = 0.0;
int counter;
for(counter = 0; counter < largest[5]; counter++)
{
//counter++;
cout <<"enter value " << counter + 1 << ": ";
cin >> amount;
largest[counter] = amount;
}
return 0;
}