bin_search return an array with 15 elements in C++











up vote
-4
down vote

favorite












I would like to create an array i_array with 15 elements and rate every element with formula



a = sin((Pi * (i - 7)) / 15)


and return it.



#include <cmath>
#include <cstddef>
#include <iostream>

void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}

void modBinSearch(double arr, double start, double end){


if (start > end){
return -1;
}
const int mitte = start +((end-start)/2);
if(arr[mitte] == 0.0){
return mitte;
}
else if(arr[mitte] > 0.0){
return modBinSearch(arr, start, mitte-1);
}
return modBinSearch(arr, mitte+1,end);


}

int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';

int arr = sinuss(i_array);
int n = sizeof(arr)/sizeof(arr[0]);
int result = modBinSearch(arr, 0, n-1);
return 0;
}


I have no idea. I don't know what my error is.



I am new in C++, because it I have a lot of problem with it:(



In my function sinuss() I should return rated elements as array and in function modBinSearch() I should return the least element who not smaller as 0.0 is. But my programm is wrong :(










share|improve this question




















  • 1




    This should not be tagged with c#
    – George Helyar
    Nov 11 at 10:23










  • Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
    – jdweng
    Nov 11 at 10:33










  • That sould not be tagged with C either.
    – Swordfish
    Nov 11 at 10:52










  • thank you. I am new in programming.:( So I changed my code. Do you mean so?
    – KG. Boys
    Nov 11 at 10:54










  • there is no point in #includeing <cmath> and <math.h>
    – Swordfish
    Nov 11 at 10:56















up vote
-4
down vote

favorite












I would like to create an array i_array with 15 elements and rate every element with formula



a = sin((Pi * (i - 7)) / 15)


and return it.



#include <cmath>
#include <cstddef>
#include <iostream>

void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}

void modBinSearch(double arr, double start, double end){


if (start > end){
return -1;
}
const int mitte = start +((end-start)/2);
if(arr[mitte] == 0.0){
return mitte;
}
else if(arr[mitte] > 0.0){
return modBinSearch(arr, start, mitte-1);
}
return modBinSearch(arr, mitte+1,end);


}

int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';

int arr = sinuss(i_array);
int n = sizeof(arr)/sizeof(arr[0]);
int result = modBinSearch(arr, 0, n-1);
return 0;
}


I have no idea. I don't know what my error is.



I am new in C++, because it I have a lot of problem with it:(



In my function sinuss() I should return rated elements as array and in function modBinSearch() I should return the least element who not smaller as 0.0 is. But my programm is wrong :(










share|improve this question




















  • 1




    This should not be tagged with c#
    – George Helyar
    Nov 11 at 10:23










  • Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
    – jdweng
    Nov 11 at 10:33










  • That sould not be tagged with C either.
    – Swordfish
    Nov 11 at 10:52










  • thank you. I am new in programming.:( So I changed my code. Do you mean so?
    – KG. Boys
    Nov 11 at 10:54










  • there is no point in #includeing <cmath> and <math.h>
    – Swordfish
    Nov 11 at 10:56













up vote
-4
down vote

favorite









up vote
-4
down vote

favorite











I would like to create an array i_array with 15 elements and rate every element with formula



a = sin((Pi * (i - 7)) / 15)


and return it.



#include <cmath>
#include <cstddef>
#include <iostream>

void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}

void modBinSearch(double arr, double start, double end){


if (start > end){
return -1;
}
const int mitte = start +((end-start)/2);
if(arr[mitte] == 0.0){
return mitte;
}
else if(arr[mitte] > 0.0){
return modBinSearch(arr, start, mitte-1);
}
return modBinSearch(arr, mitte+1,end);


}

int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';

int arr = sinuss(i_array);
int n = sizeof(arr)/sizeof(arr[0]);
int result = modBinSearch(arr, 0, n-1);
return 0;
}


I have no idea. I don't know what my error is.



I am new in C++, because it I have a lot of problem with it:(



In my function sinuss() I should return rated elements as array and in function modBinSearch() I should return the least element who not smaller as 0.0 is. But my programm is wrong :(










share|improve this question















I would like to create an array i_array with 15 elements and rate every element with formula



a = sin((Pi * (i - 7)) / 15)


and return it.



#include <cmath>
#include <cstddef>
#include <iostream>

void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}

void modBinSearch(double arr, double start, double end){


if (start > end){
return -1;
}
const int mitte = start +((end-start)/2);
if(arr[mitte] == 0.0){
return mitte;
}
else if(arr[mitte] > 0.0){
return modBinSearch(arr, start, mitte-1);
}
return modBinSearch(arr, mitte+1,end);


}

int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';

int arr = sinuss(i_array);
int n = sizeof(arr)/sizeof(arr[0]);
int result = modBinSearch(arr, 0, n-1);
return 0;
}


I have no idea. I don't know what my error is.



I am new in C++, because it I have a lot of problem with it:(



In my function sinuss() I should return rated elements as array and in function modBinSearch() I should return the least element who not smaller as 0.0 is. But my programm is wrong :(







c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 21:11

























asked Nov 11 at 10:14









KG. Boys

136




136








  • 1




    This should not be tagged with c#
    – George Helyar
    Nov 11 at 10:23










  • Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
    – jdweng
    Nov 11 at 10:33










  • That sould not be tagged with C either.
    – Swordfish
    Nov 11 at 10:52










  • thank you. I am new in programming.:( So I changed my code. Do you mean so?
    – KG. Boys
    Nov 11 at 10:54










  • there is no point in #includeing <cmath> and <math.h>
    – Swordfish
    Nov 11 at 10:56














  • 1




    This should not be tagged with c#
    – George Helyar
    Nov 11 at 10:23










  • Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
    – jdweng
    Nov 11 at 10:33










  • That sould not be tagged with C either.
    – Swordfish
    Nov 11 at 10:52










  • thank you. I am new in programming.:( So I changed my code. Do you mean so?
    – KG. Boys
    Nov 11 at 10:54










  • there is no point in #includeing <cmath> and <math.h>
    – Swordfish
    Nov 11 at 10:56








1




1




This should not be tagged with c#
– George Helyar
Nov 11 at 10:23




This should not be tagged with c#
– George Helyar
Nov 11 at 10:23












Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
– jdweng
Nov 11 at 10:33




Where is the memory declared for the returned data? You can't return an array to a pointer from a function. A function variables a placed on the execution stack. When you return from a function the stack variables are disposed and no longer exist. So you have to declare the memory for the array in the main so the data is copied on the return from the method before the data is disposed.
– jdweng
Nov 11 at 10:33












That sould not be tagged with C either.
– Swordfish
Nov 11 at 10:52




That sould not be tagged with C either.
– Swordfish
Nov 11 at 10:52












thank you. I am new in programming.:( So I changed my code. Do you mean so?
– KG. Boys
Nov 11 at 10:54




thank you. I am new in programming.:( So I changed my code. Do you mean so?
– KG. Boys
Nov 11 at 10:54












there is no point in #includeing <cmath> and <math.h>
– Swordfish
Nov 11 at 10:56




there is no point in #includeing <cmath> and <math.h>
– Swordfish
Nov 11 at 10:56












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










Define a type of what you desire. Suggesting a std::array<double,15>. It makes coding what you want more natural.



    #include <array>
#include <iostream>
#include <cmath>

using namespace std;

using ArrOf15Dbl = array<double, 15>;

ArrOf15Dbl sinuss() {
ArrOf15Dbl i_array;

for (int i = 0; i < 15; ++i) {

i_array[i] = sin((M_PI * (i - 7)) / 15);
cout << i_array[i] << ' ';
}
cout << 'n';
return i_array;
}

int main() {
ArrOf15Dbl x = sinuss();
for (auto i : x) {
cout << i << ' ';
}
cout << 'n';
}


But returning arrays from a function is not possible with C++98/03. So one solution is to allocate the needed memory dynamically, but don't forget to release it later!



    #include <cmath>
#include <cstddef>
#include <iostream>

int const kArrSiz = 15;

// OBS: caller assumes ownership of array pointer!
// Must be deleted with "delete foobar;"
double* sinuss() {
double* i_array = new double[kArrSiz];

for (int i = 0; i < kArrSiz; ++i) {

i_array[i] = std::sin((M_PI * (i - 7)) / kArrSiz);
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return i_array;
}

int main() {
double* x = sinuss();
for (int i = 0; i < kArrSiz; ++i) {
std::cout << x[i] << ' ';
}
std::cout << 'n';
delete x;
return EXIT_SUCCESS;
}


But with a change of interface to your function, it can be made safer by requiring the caller to allocate the array and your function instead fills it with your required values.



    void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}

int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return EXIT_SUCCESS;
}





share|improve this answer























  • mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
    – KG. Boys
    Nov 11 at 15:54










  • @KG.Boys What compiler are you running and with which version of C++ are you trying to use?
    – Bo R
    Nov 11 at 16:59










  • I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
    – KG. Boys
    Nov 11 at 18:32










  • So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
    – KG. Boys
    Nov 11 at 18:43










  • @KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add -std=gnu++0x to the compile command.
    – Bo R
    Nov 11 at 19:13


















up vote
2
down vote













There are usually better ways to write loops that use a sequence of floating-point values, such as using an integer for loop control and calculating the floating-point value from the integer in each iteration. (Alternatively, you can use a floating-point object for loop control but take care to use only integer values for the loop expressions.)






share|improve this answer





















  • thank you Ichanged my code.Do you mean so?
    – KG. Boys
    Nov 11 at 11:15











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247709%2fbin-search-return-an-array-with-15-elements-in-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










Define a type of what you desire. Suggesting a std::array<double,15>. It makes coding what you want more natural.



    #include <array>
#include <iostream>
#include <cmath>

using namespace std;

using ArrOf15Dbl = array<double, 15>;

ArrOf15Dbl sinuss() {
ArrOf15Dbl i_array;

for (int i = 0; i < 15; ++i) {

i_array[i] = sin((M_PI * (i - 7)) / 15);
cout << i_array[i] << ' ';
}
cout << 'n';
return i_array;
}

int main() {
ArrOf15Dbl x = sinuss();
for (auto i : x) {
cout << i << ' ';
}
cout << 'n';
}


But returning arrays from a function is not possible with C++98/03. So one solution is to allocate the needed memory dynamically, but don't forget to release it later!



    #include <cmath>
#include <cstddef>
#include <iostream>

int const kArrSiz = 15;

// OBS: caller assumes ownership of array pointer!
// Must be deleted with "delete foobar;"
double* sinuss() {
double* i_array = new double[kArrSiz];

for (int i = 0; i < kArrSiz; ++i) {

i_array[i] = std::sin((M_PI * (i - 7)) / kArrSiz);
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return i_array;
}

int main() {
double* x = sinuss();
for (int i = 0; i < kArrSiz; ++i) {
std::cout << x[i] << ' ';
}
std::cout << 'n';
delete x;
return EXIT_SUCCESS;
}


But with a change of interface to your function, it can be made safer by requiring the caller to allocate the array and your function instead fills it with your required values.



    void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}

int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return EXIT_SUCCESS;
}





share|improve this answer























  • mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
    – KG. Boys
    Nov 11 at 15:54










  • @KG.Boys What compiler are you running and with which version of C++ are you trying to use?
    – Bo R
    Nov 11 at 16:59










  • I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
    – KG. Boys
    Nov 11 at 18:32










  • So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
    – KG. Boys
    Nov 11 at 18:43










  • @KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add -std=gnu++0x to the compile command.
    – Bo R
    Nov 11 at 19:13















up vote
0
down vote



accepted










Define a type of what you desire. Suggesting a std::array<double,15>. It makes coding what you want more natural.



    #include <array>
#include <iostream>
#include <cmath>

using namespace std;

using ArrOf15Dbl = array<double, 15>;

ArrOf15Dbl sinuss() {
ArrOf15Dbl i_array;

for (int i = 0; i < 15; ++i) {

i_array[i] = sin((M_PI * (i - 7)) / 15);
cout << i_array[i] << ' ';
}
cout << 'n';
return i_array;
}

int main() {
ArrOf15Dbl x = sinuss();
for (auto i : x) {
cout << i << ' ';
}
cout << 'n';
}


But returning arrays from a function is not possible with C++98/03. So one solution is to allocate the needed memory dynamically, but don't forget to release it later!



    #include <cmath>
#include <cstddef>
#include <iostream>

int const kArrSiz = 15;

// OBS: caller assumes ownership of array pointer!
// Must be deleted with "delete foobar;"
double* sinuss() {
double* i_array = new double[kArrSiz];

for (int i = 0; i < kArrSiz; ++i) {

i_array[i] = std::sin((M_PI * (i - 7)) / kArrSiz);
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return i_array;
}

int main() {
double* x = sinuss();
for (int i = 0; i < kArrSiz; ++i) {
std::cout << x[i] << ' ';
}
std::cout << 'n';
delete x;
return EXIT_SUCCESS;
}


But with a change of interface to your function, it can be made safer by requiring the caller to allocate the array and your function instead fills it with your required values.



    void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}

int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return EXIT_SUCCESS;
}





share|improve this answer























  • mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
    – KG. Boys
    Nov 11 at 15:54










  • @KG.Boys What compiler are you running and with which version of C++ are you trying to use?
    – Bo R
    Nov 11 at 16:59










  • I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
    – KG. Boys
    Nov 11 at 18:32










  • So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
    – KG. Boys
    Nov 11 at 18:43










  • @KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add -std=gnu++0x to the compile command.
    – Bo R
    Nov 11 at 19:13













up vote
0
down vote



accepted







up vote
0
down vote



accepted






Define a type of what you desire. Suggesting a std::array<double,15>. It makes coding what you want more natural.



    #include <array>
#include <iostream>
#include <cmath>

using namespace std;

using ArrOf15Dbl = array<double, 15>;

ArrOf15Dbl sinuss() {
ArrOf15Dbl i_array;

for (int i = 0; i < 15; ++i) {

i_array[i] = sin((M_PI * (i - 7)) / 15);
cout << i_array[i] << ' ';
}
cout << 'n';
return i_array;
}

int main() {
ArrOf15Dbl x = sinuss();
for (auto i : x) {
cout << i << ' ';
}
cout << 'n';
}


But returning arrays from a function is not possible with C++98/03. So one solution is to allocate the needed memory dynamically, but don't forget to release it later!



    #include <cmath>
#include <cstddef>
#include <iostream>

int const kArrSiz = 15;

// OBS: caller assumes ownership of array pointer!
// Must be deleted with "delete foobar;"
double* sinuss() {
double* i_array = new double[kArrSiz];

for (int i = 0; i < kArrSiz; ++i) {

i_array[i] = std::sin((M_PI * (i - 7)) / kArrSiz);
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return i_array;
}

int main() {
double* x = sinuss();
for (int i = 0; i < kArrSiz; ++i) {
std::cout << x[i] << ' ';
}
std::cout << 'n';
delete x;
return EXIT_SUCCESS;
}


But with a change of interface to your function, it can be made safer by requiring the caller to allocate the array and your function instead fills it with your required values.



    void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}

int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return EXIT_SUCCESS;
}





share|improve this answer














Define a type of what you desire. Suggesting a std::array<double,15>. It makes coding what you want more natural.



    #include <array>
#include <iostream>
#include <cmath>

using namespace std;

using ArrOf15Dbl = array<double, 15>;

ArrOf15Dbl sinuss() {
ArrOf15Dbl i_array;

for (int i = 0; i < 15; ++i) {

i_array[i] = sin((M_PI * (i - 7)) / 15);
cout << i_array[i] << ' ';
}
cout << 'n';
return i_array;
}

int main() {
ArrOf15Dbl x = sinuss();
for (auto i : x) {
cout << i << ' ';
}
cout << 'n';
}


But returning arrays from a function is not possible with C++98/03. So one solution is to allocate the needed memory dynamically, but don't forget to release it later!



    #include <cmath>
#include <cstddef>
#include <iostream>

int const kArrSiz = 15;

// OBS: caller assumes ownership of array pointer!
// Must be deleted with "delete foobar;"
double* sinuss() {
double* i_array = new double[kArrSiz];

for (int i = 0; i < kArrSiz; ++i) {

i_array[i] = std::sin((M_PI * (i - 7)) / kArrSiz);
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return i_array;
}

int main() {
double* x = sinuss();
for (int i = 0; i < kArrSiz; ++i) {
std::cout << x[i] << ' ';
}
std::cout << 'n';
delete x;
return EXIT_SUCCESS;
}


But with a change of interface to your function, it can be made safer by requiring the caller to allocate the array and your function instead fills it with your required values.



    void sinuss(double (&arr)[15]) {
for (int i = 0; i < 15; ++i) {
arr[i] = std::sin((M_PI * (i - 7)) / 15);
std::cout << arr[i] << ' ';
}
std::cout << 'n';
}

int main() {
double i_array[15];
sinuss(i_array);
for (int i = 0; i < 15; ++i) {
std::cout << i_array[i] << ' ';
}
std::cout << 'n';
return EXIT_SUCCESS;
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 17:32

























answered Nov 11 at 14:00









Bo R

612110




612110












  • mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
    – KG. Boys
    Nov 11 at 15:54










  • @KG.Boys What compiler are you running and with which version of C++ are you trying to use?
    – Bo R
    Nov 11 at 16:59










  • I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
    – KG. Boys
    Nov 11 at 18:32










  • So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
    – KG. Boys
    Nov 11 at 18:43










  • @KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add -std=gnu++0x to the compile command.
    – Bo R
    Nov 11 at 19:13


















  • mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
    – KG. Boys
    Nov 11 at 15:54










  • @KG.Boys What compiler are you running and with which version of C++ are you trying to use?
    – Bo R
    Nov 11 at 16:59










  • I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
    – KG. Boys
    Nov 11 at 18:32










  • So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
    – KG. Boys
    Nov 11 at 18:43










  • @KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add -std=gnu++0x to the compile command.
    – Bo R
    Nov 11 at 19:13
















mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
– KG. Boys
Nov 11 at 15:54




mmh, I didn't understand your code. If I copy and pasta,there are a lot of errors
– KG. Boys
Nov 11 at 15:54












@KG.Boys What compiler are you running and with which version of C++ are you trying to use?
– Bo R
Nov 11 at 16:59




@KG.Boys What compiler are you running and with which version of C++ are you trying to use?
– Bo R
Nov 11 at 16:59












I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
– KG. Boys
Nov 11 at 18:32




I use GCC, and gcc --version gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
– KG. Boys
Nov 11 at 18:32












So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
– KG. Boys
Nov 11 at 18:43




So, thank you. The second one works , I got in output all elements, but I need it as array, because I must write my second function , so that I can use this array in my second function. :(
– KG. Boys
Nov 11 at 18:43












@KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add -std=gnu++0x to the compile command.
– Bo R
Nov 11 at 19:13




@KG.Boys There is partial C++11 support in gcc 4.8.2. You might want to try and add -std=gnu++0x to the compile command.
– Bo R
Nov 11 at 19:13












up vote
2
down vote













There are usually better ways to write loops that use a sequence of floating-point values, such as using an integer for loop control and calculating the floating-point value from the integer in each iteration. (Alternatively, you can use a floating-point object for loop control but take care to use only integer values for the loop expressions.)






share|improve this answer





















  • thank you Ichanged my code.Do you mean so?
    – KG. Boys
    Nov 11 at 11:15















up vote
2
down vote













There are usually better ways to write loops that use a sequence of floating-point values, such as using an integer for loop control and calculating the floating-point value from the integer in each iteration. (Alternatively, you can use a floating-point object for loop control but take care to use only integer values for the loop expressions.)






share|improve this answer





















  • thank you Ichanged my code.Do you mean so?
    – KG. Boys
    Nov 11 at 11:15













up vote
2
down vote










up vote
2
down vote









There are usually better ways to write loops that use a sequence of floating-point values, such as using an integer for loop control and calculating the floating-point value from the integer in each iteration. (Alternatively, you can use a floating-point object for loop control but take care to use only integer values for the loop expressions.)






share|improve this answer












There are usually better ways to write loops that use a sequence of floating-point values, such as using an integer for loop control and calculating the floating-point value from the integer in each iteration. (Alternatively, you can use a floating-point object for loop control but take care to use only integer values for the loop expressions.)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 10:23









Md. Mokammal Hossen Farnan

577320




577320












  • thank you Ichanged my code.Do you mean so?
    – KG. Boys
    Nov 11 at 11:15


















  • thank you Ichanged my code.Do you mean so?
    – KG. Boys
    Nov 11 at 11:15
















thank you Ichanged my code.Do you mean so?
– KG. Boys
Nov 11 at 11:15




thank you Ichanged my code.Do you mean so?
– KG. Boys
Nov 11 at 11:15


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247709%2fbin-search-return-an-array-with-15-elements-in-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation