I have a simple if statement going from 0-360 in 30 degree increments. I want to store those values into into an array because I need to use them for simple calculations later. I think I need an dynamic array because what I tried below is not working.

So I guess I have two questions. One is how much I get my array to store the values of x1.

Also, when I get my array working and lets say I want to do a calculation with 30 (lets say array[1]) can I just do randomvariable = array[1] * 2.0?

#include<iostream>
#include <vector>
using namespace std;



int main()
{

double l1=25.0, l2=5.0, l3=20.0, l4=10.0 x1;
int array1[13];


for(x1=0.0; x1<361.0; x1+=30.0){
x1 = array1;
}



char x;
std::cin>>x;

return 0;
}

Regards,

-m

Recommended Answers

All 7 Replies

the for statement can't use floating point types as the variant. You are allowed integers and enumeration types.

Your going about this the wrong way, to initialize an array you must access each element..Like so

#include<iostream>
#include <vector>
using namespace std;

int main()
{
	double l1=25.0, l2=5.0, l3=20.0, l4=10.0, x1;
	int array1[13];
	int i = 0;

	for(x1=0.0; x1<361.0; x1+=30.0)
	{
		array1[i++] = x1;
	}

	for(i = 0; i < 13; ++i)
	{
		std::cout << array1[i] << std::endl;
	}

	return 0;
}

the for statement can't use floating point types as the variant. You are allowed integers and enumeration types.

Are you sure about your statement?

Sorry, I take that back; must only apply to 'c'; Just tired it on VC++6 and it worked.

Okay I understand you're method. Just for future reference if I did know know how many elements I had (in this case I had 13).

Would I have to declare a pointer?

Sorry, I take that back; must only apply to 'c'; Just tired it on VC++6 and it worked.

Again, are you sure about your statement?

Okay I understand you're method. Just for future reference if I did know know how many elements I had (in this case I had 13).

Would I have to declare a pointer?

An array name is a pointer. You mean, can you dynamically allocate the memory? Yes but if the number of array elements remains constant its better to use a static array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.