please help im lost
Jul 10, 2013 at 4:51am UTC
i get the error stdafx.h no file or directory. why is that?? thanks!!!
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
#include "stdafx.h"
#include<iostream>
using namespace std;
int *Shifted_array(const int *,int ) ;
int main ()
{
int array[20];
int *Shifted;
int size;
int i;
cout << "Enter size of array: " << endl;
cin > size;
cout << "Enter elements: " ;
for (i=0;i<size;i++)
cin >> array[i];
Shifted=Shifted_array(array,size);
cout << "The elements after shifting the array: " << endl;
for (i=0;i<size+1;i++)
cout << *(Shifted+i) << endl;
system("pause" );
}
int *Shifted_array(const int *arr,int size)
{
int *New_array=new int [size+1];
int i,m;
New_array[0] = 0;
m=1;
for (i=0;i<size;i++)
{
New_array[m] = arr[i];
m++;
}
return New_array;
}
Jul 10, 2013 at 4:56am UTC
stdafx.h
is used in VS (visual studio) only. You don't need it (for this program). Just delete it or comment it out.
Jul 10, 2013 at 4:59am UTC
do you know whats wrong with my code? i took it out and have a ton of errors.
the problem is to Write a function that accepts an int array and the array s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to elem
Jul 10, 2013 at 5:57am UTC
Here is your fixed code:
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
#include<iostream>
using namespace std;
int *Shifted_array(const int *arr,int size)
{
int *New_array=new int [size+1];
int i,m;
New_array[0] = 0;
m=1;
for (i=0;i<size;i++)
{
New_array[m] = arr[i];
m++;
}
return New_array;
}
int main (void )
{
int array[20];
int *Shifted;
int size;
int i;
cout << "Enter size of array: " << endl;
cin >> size;
cout << "Enter elements: " ;
for (i=0;i<size;i++)
cin >> array[i];
Shifted=Shifted_array(array,size);
cout << "The elements after shifting the array: " << endl;
for (i=0;i<size+1;i++)
cout << *(Shifted+i) << endl;
system("pause" );
}
Topic archived. No new replies allowed.