|
-
April 27th, 2006, 10:50 PM
#1
Need help with arrays
I'm trying to write this program which doesn't yield the output desired.
Here's the prompt:
Write a C++ program that declares an array alpha of 50 components of the type double. Initialize the array so that the first 25 components are equal to the square of the index variable and the last 25 components are equal to three times the index variable. Then just output the array.
Here's what I have:
#include <iostream>
using namespace std;
int main(){
double alpha[50];
int counter;
int square;
int times3;
for(counter = 0; counter <= 24; counter++)
{
square = counter * counter;
square = alpha[counter];
}
for(counter = 25; counter <= 49 && counter > 24; counter++)
{
times3 = counter * 3;
times3 = alpha[counter];
}
for(counter = 0; counter <= 49; counter++)
{
cout << " ";
cout << alpha[counter];
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|