C++ array program kinks Help!!



Hey!! I'm new to C++, this is the final program of my semester and I am stuck sooooo hard...



I have the code laid out and it will compile but my functions wont work like I want them too. here is the code:



```
#include<iostream>

using namespace std;


void getlist(int[], int&);

void putlist (const int[], int);

float mean_average (const int[], int);

int MinIndex (const int[], int);

void left_rotate (int[], int);



const int MAXSIZE = 50;


int main()

{
int mylist[MAXSIZE];
int num_items;

    
    getlist (mylist, num_items);
    putlist (mylist, num_items);
    MinIndex (mylist, num_items);
    mean_average(mylist, num_items);
    left_rotate (mylist, num_items);
    
    
    system ("PAUSE");
    return 0;
}

void getlist(int mylist[], int &num_items)    
{
    
    cout << "Enter the number of Array Elements, Maximum " << MAXSIZE << endl;
    cin >> num_items;
    
    for (int i = 0; i < num_items; i ++)
        {
        cout << "Enter the next array element\n";
        cin >> mylist[i];
        }
}

void putlist (const int mylist[], int num_items)
{    
    cout << "Array elements\n";
    for (int i = 0; i < num_items; i ++)
        {
    cout << i << " " << mylist [i] << endl;
         }
}    
int MinIndex (const int mylist[], int num_items)
{
                    int min =mylist[0];
               
               for(int i = 0; i < num_items; i++)
                       {
                        if (min <= mylist[i])
                        min = i;
                       }
                       
			cout<< "The address of the smallest number is "<< min<<endl;
		 return min;
}
float mean_average(const int mylist[],int num_items)
{
      int sum=0;
      float average;
      
      
             
	  for(int i= 0; i <= num_items; i++)
	  {
	  sum= sum + mylist[i];
      }
      		average= sum/num_items;
       
	cout<< "The average value is: "<<average<<endl; 
	 return average;

}
void left_rotate (int mylist[], int num_items)
{
	int temp = mylist[0]; 
		for(int i = 0; i < num_items-1; i++)
		{
                cout << "The new array elements are:\n";
           	    mylist[i] = mylist[i+1]; 
                
                cout << i << " " << mylist [i]<<endl;
                mylist[num_items-1] = temp;
                cout<<temp;
		}		
}
```

The array left rotate does rotate but the value stored in temp wont appear, and the calculations for MinIndex and mean\_average are just not working out.... I've looked all over the web, but even when I find codes that are identical they still don't work. what am I doing wrong?? I would write it simpler but the format is require and all the functions were dictated so I cant alter them. This is due tuesday- please help!!
For the most part the code is pretty good. You made a few minor errors that would be expected since you are still starting out but you should really work on consistency in indentation since it is harder to read and edit (you will really notice this later on) so you should get into the habit of trying to make your code look nice early on.



  

I commented in a few places where I made changes.



```
#include <iostream>
#include <cstdlib> //needed for system() because not all compilers include this header by default

using namespace std;

//the way you are using your functions you can/should have them all return void
void getlist(int[], int&);
void putlist (const int[], int);
void mean_average (const int[], int);
void MinIndex (const int[], int);
void left_rotate (int[], int);

const int MAXSIZE = 50;

int main()
{
	int mylist[MAXSIZE];
	int num_items;

	getlist(mylist, num_items);
	putlist(mylist, num_items);
	MinIndex(mylist, num_items);
	mean_average(mylist, num_items);
	left_rotate(mylist, num_items);

	system ("PAUSE");
	return 0;
}

void getlist(int mylist[], int &num_items)
{
	cout << "Enter the number of Array Elements, Maximum " << MAXSIZE << endl;
	cin >> num_items;

	for( int i = 0; i < num_items; i++ )
	{
		cout << "Enter the next array element: ";
		cin >> mylist[i];
	}
	cout << endl;
}

void putlist(const int mylist[], int num_items)
{
	cout << endl << "Array elements\n";
	for( int i = 0; i < num_items; i++ )
	{
		cout << i << " " << mylist [i] << endl;
	}
}

void MinIndex(const int mylist[], int num_items)
{
	int min = 0; //assuming min index is 0 (not the actual value there)

	for( int i = 0; i < num_items; i++ )
	{
		if( mylist[i] < mylist[min] ) //compare the values at each index
			min = i;
	}

	cout << endl << "The address of the smallest number is " << min << endl;
}

void mean_average(const int mylist[],int num_items)
{
	int sum = 0;
	float average;

	for( int i= 0; i < num_items; i++ ) //use < if your are using num_items or <= if you use num_items-1
	{
		sum += mylist[i];
	}
	average = sum / num_items;

	cout << endl << "The average value is: " << average << endl;
}

//used a bit of your code but rewrote most of left_rotate (this seems more like a left shift)
void left_rotate(int mylist[], int num_items)
{
	int temp = mylist[0];
	for( int i = 0; i < num_items-1; i++ )
	{
		mylist[i] = mylist[i+1];
	}
	mylist[num_items-1] = temp;

	cout << endl << "The new array elements are:\n";
	for( int i = 0; i < num_items; i++ )
		cout << mylist[i] << " ";
	cout << endl << endl;
}
```
you write an int, but try to receive a c-string, that can not work.

the radio will not be available (i.e. have a packet received) 99.9% of the time,

introducing a delay and printing something if that is the case is just crazy.

so your code seems to be copy and pasted crap without any understandin… you are mixing up "for all iterators i" with "for some specific kind of iterator i".

what if i decide to call foo<std::vec::intoiter<string>>? then you have a function that takes an intoiter<string>, but you tried to call it with an skip<intoiter<string>>, which is a different type. hence a type mi… I'm not sure where it comes from `vlist`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. It should probably be part of the user state of the parser. For now, let's assume this is the top-level definition:



```
vlist :: [(String, Float)]
vlist = undefined -- fill in the blanks...

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

I assume you are using `Parsec`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. You can simplify your parser:



```
primary :: Parser Float
primary = choice [ between (symbol "(") (symbol ")") expression
                 , do { ident <- identifier
                      ; case lookup ident vlist of
                          Nothing -> fail $ "No such identifier: " ++ ident
                          Just v -> return v
                      }
                 ]

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```


  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

You have several options for solving this problem. Here I used the parader monad function `fail`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. This will cause the parser to return a value `Left parserError`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

. Alternatively, you can replace `error`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

with `fail`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

, which will result in an error that can only be handled in a monad `IO`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

.


 **Note** . To add `vlist`
  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

a parser as a state, you need to define a new parser type with this state:



```
data MyParserState = MyParserState { vlist :: [(String, Float)] }
type MyParser = CharParser MyParserState

-- these parsers now need to return MyParser type!
symbol :: String -> MyParser String
identifier :: MyParser String
expression :: MyParser Float

primary :: MyParser Float
primary = choice [ between (symbol "(") (symbol ")") expression
                 , do { st <- getState
                      ; ident <- identifier
                      ; case lookup ident $ vlist st of
                          Nothing -> fail $ "No such identifier: " ++ ident
                          Just v -> return v
                      }
                 ]

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
``` histogram  divide data o equal width o no overlapping  bar chart o skew­ pulls direction of mean o symmetric numeric summary center, spread, and location  greek letters for population  roman letters for statistics 1. mean  µ= population mean  x bar= sanple mean o ∑ xi  all over n= sample mean  k=0 2. mean vs. median a. mean used the most b. n is small when outliers occur c. use median, mean is too affected spread 1. range (max­min) a. sensitive to outliers 2. iqr a. not sensitive to outliers variability­ xi­x bar `for i in count:` means `for i in 7:`, which won't work. The bit after the `in` should be of an iterable type, not a number. Try this:



```
for i in range(count):

``` The problem is that your pair's closure must return two different types of objects: int if you ask for "con", and the next closure on the line if you ask for "crd".


Here's one possible implementation:


Use a speaker so you can come back.



```
public static Func<string, dynamic> Pair(int x, Func<string, dynamic> y)
{
    Func<string, dynamic> pair =
           (a) =>
           {
               if (a == "con") return x;
               if (a == "crd") return y;
               throw new Exception();
           };

    return pair;
}

public static void Print(Func<string, dynamic> pair)
{
    while (true)
    {
        var next = pair("crd");
        Console.WriteLine((next == null ? "-":"+") +"> " + pair("con"));
        if (next != null)
        {
            Console.WriteLine("|");
            pair = (x) => next(x);
            continue;
        }
        break;
    }
}

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```


  




 (adsbygoogle = window.adsbygoogle || []).push({});
 
  

Test:



```
var pair = Pair(1,
            Pair(2,
                  Pair(3,
                        Pair(4, null))));

Print(pair);

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
```

output:



```
+> 1
|
+> 2
|
+> 3
|
-> 4

        

        
        
        
 (adsbygoogle = window.adsbygoogle || []).push({});
 
        

    
``` you are accidentally creating an array inside of an array: the .split() method returns an array, so you can simply set storywords equal to story.split(' '), instead of placing it inside of an array.

in its current form, storywords does only have length 1, because it only has one index: the resultan… hi,

sorry you are having issues with this. this is a known bug that was fixed in 2.24. the index of the loop is of an unsigned type in the generated c++ in 2.23. and since there are no negative numbers in unsigned types -1 becomes max integer.

issue where we found this: [https://github.com/stan-dev…](https://github.com/stan-dev/stanc3/issues/536) matlab does not need a |return| statement to return a value. to return a value you simply need to list it as an output argument of the function:

 function [output1,output2,...] = fun\_name(input1,input2,...)

you have specified an output argument |rad|, but then have totally ignored this inside your code an never allocated any value to it. you should try something like this:

 function rad = radial(n,m);
 rad = ... whatever rad is;
 end

of course this is explained quite clearly in the introductory tutorials:

<http://www.mathworks.com/help/matlab/getting-started-with-matlab.html>

and also the <http://www.mathworks.com/help/matlab/ref/function.html |function|> documentation:

<http://www.mathworks.com/help/matlab/ref/function.html>

read the documentation. it tells you how matlab works.

if you want to store all of the values of |rad| in a loop then you can use indexing. The behaviour must be because you are appending the same array to both of the arrays.  

Try appending a different array for cell*code and cell*type separately.