help with arrays ..

hi guys..

so this is my code ,,and i wish if someone could tell me why the output give the same result for calculating the hypotenuse of a right triangle everytime the program starts ..!!?

i hope someone would help... ow and i don;t know why my setprecision is not workin to??? HELP..!!!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<iostream>
#include<string>
#include<conio.h>
#include<stdlib.h>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include<cmath>
using namespace std;
void FillArray(int arr[],int size);
void PrintFirstArray(int arr[],int size);
void PrintSecondArray(int arr[],int size);
void hypotenuse(int side1[],int side2[],int size);
int main()
{
	int size=0;
	cout<<"How long are your arrays? ";
	cin>>size;

	int *side1=new int[size];
	int *side2=new int [size];
	
	FillArray(side1,size);
	FillArray(side2,size);
	PrintFirstArray(side1,size);
	PrintSecondArray(side2,size);

	hypotenuse(side1,side2,size);
	
	

	return 0;
}

void FillArray(int arr[],int size)
{
	int random=0;
	int R_size=0;
	bool full=false;

	for(int i=0;;i++)
	{ 
		srand(time(0)); ///This function used to give c++ some time to store random nunber and generate it 
		random=rand() % 100 ; //create random number between 1-100
		int * x = std::find (arr, arr+size, random); //check if element already in array (best way)
		
		if (x != arr+size)  //keep track of indexing 
			  i++;
		  else
		  {
			arr[i]= random;
			R_size++;
			if(Rsize==size)
				full=true;
		  }

		  if(full=true)
			  break;
	}
	
}

void PrintirstArray(int arr[],int size)
{
	cout<<"Array side1 is : ";
	for(int i=0;i<size;i++)
		cout<<"  "<<arr[i]<<"    ";
	cout<<endl;
}
void PrintecondArray(int arr[],int size)
{
	cout<<"Array side2 is : ";
	for(int i=0;i<size;i--)
		cout<<"  "<<arr[i]<<"    ";
	cout<<endl;
}

void hypotenuse(int side1[],int side2[],int size)
{
	float *hy= float [size];
	
	(int i=0;i<+size;i++)
	{
		hy[i]=((side1[i]*side1[i])+(side2[i]+side2[i]));
		hy[i]=sqrt(hy[i]);
	}

	for(i=0;i<size;i++)
		cout<<" "<< hy[i]<<" ";
	cout<<endl;
}




this is my sample run:

Sample Output:
How long are your arrays? 6
Array side1 is: 2 34 15 42 29 10
Array side2 is: 38 13 21 17 23 49
After calling Hypotenuse function
Array hypotenuse is:
38.05 36.4 25.8 45.3 37.01 50.01




please help me thank yewwwww _(VnV'')_
Last edited on
_(._. )_ whhy am i all alone in here?
Why do you call srand more than once?

Why cannot two elements in array be identical?

What is line 87?

Wouldn't just one PrintArray() be enough?

You never deallocate dynamic memory. Do not learn such habit.

What do you print after setting precision?
Last edited on
it,s just all what my brain got from this question..!!
it should be random it`s what it says here...

Write a program that uses a random generator to fill two arrays side1 and side2 between 1 and 100. The program calls a function hypotenuse that takes two arrays to calculate and save the length of the hypotenuse in an array of a right triangle of the other two sides and returns the hypotenuse array.



it need to print the calculated hy[]
answer with only two decimals..!!

line 87 is to calculate the hypotenuse for a right triangle..!!

keskiverto
i give up.. thanks anyway
Last edited on
Topic archived. No new replies allowed.