Hi i put most of the //discriptions in so it should be easy to tell what is suppose tohappen where. It is longer then it seems, its very beginner level. Also im not sure i did the functions and arrays perfect.
Errors i have before i have been able to run are:
line 44 `main' must return `int'
line 115 expected primary-expression before "int"
line 115 expected primary-expression before "int"
line 115 expected primary-expression before "int"
line 127 expected declaration before '}' token
/***********************************************************************
*Program Description: This program is designed to insert numbers into
* an array in ascending order. After the numbers have been inserted
* the user will have the option to display the numbers back to the
* screen in either ascending or descending order. A function will
* be used to insert the number into the correct position in the
* array. Another function will be used to display the numbers back
* to the screen.
*
*BEGIN - Lab 9, Creating my own functions
* Init array count to 0
* Prompt user for first input or QUIT
* WHILE (input is not QUIT)
* Call function to insert the value into the array
* Increment the array count by 1
* IF (the Array is now full)
* Make input = QUIT to exit the loop
* ELSE //the array is not full
* Prompt user for next input or QUIT
* END IF
* END WHILE
* Clear Screen
* Ask user if they want to display in Ascending or Descending order
* Display Title
* IF (User wants ascending order)
* Call display function to display array values in asc order
* ELSE
* Call display function to display array values in desc order
* END IF
*END - Lab 9 - Creating my own functions
*********************************************************************/
#include <iostream>
#include <iomanip>
//local functions stored at bottom of the file
void array_insert(int, int, int[]); //insert 1 value into array
void array_disp (int, int, int[]); //disp array in asc or desc
using namespace std;
void main()
{
//local constants
const int ARRAY_SIZE = 5;
const int QUIT =-99;
const char ASCENDING ='A';
const char DESCENDING ='D';
//local variables
int Array[ARRAY_SIZE]; //an array to store the integers
int count = 0 ; //a count of #s stored in the array
int Num_Input ; //the number input by the user
int Result ; //Result of number for arrary display
char Letter_Code; //For acending or decending
/*******************************************************/
//Init array count to 0
for (count =0; count < ARRAY_SIZE; count++)
{
//Prompt user for first input or QUIT
cout << "Enter first input or Quit";
cin >> Num_Input;
//WHILE (input is not QUIT)
while (Num_Input =! QUIT)
{
//Call function to insert the value into the array
void array_insert(int, int, int[]);
//Increment the array count by 1
count++;
//IF (the Array is now full)
if (count > ARRAY_SIZE)
{
//Make input = QUIT to exit the loop
Num_Input = QUIT;
}
//ELSE //the array is not full
else if (count < ARRAY_SIZE)
{
//Prompt user for next input or QUIT
cout << "Enter number or Quit";
cin >> Num_Input;
}
//END IF
//END WHILE
}
//Clear Screen
system("cls");
//Ask user if they want to display in Ascending or Descending order
cout << "Enter A for Acending order and D for Decending order";
cin >> Result ;
//Display Title
cout << "\n\n\n\n\n";
cout << "The Numbers";
Letter_Code = toupper(Letter_Code);
//IF (User wants ascending order)
if (Result == DESCENDING)
{
//Call display function to display array values in asc order
array_insert(int Num, int Count, int Array[]);
}
//ELSE
else if (Result == ASCENDING)
{
//Call display function to display array values in desc order
}
//END IF
}
}
} //end main program
}
/**********************************************************************
*Program Name : Array Insert in Ascending Order
*Author :
*Date :
*Course/Section :
*Program Description: This function is designed to insert a single
* value into an array in ascending order. The number, the count
* of elements currently in the array, and the array will be passed
* in as parameters. The function will first find the correct
* position where the number should be inserted. It will then move
* of the values that are greater than the number down 1 position in
* the array starting with the end of the array. The number will
* then be stored in the correct position
*
*BEGIN - Ins # in array in asc order (int Num,int Count.int Array[])
* Init array position counter (pos) to 0 (beginning of array)
* WHILE (Not at the end of the array && the insert position is not found)
* Increment pos
* END WHILE
* FOR (Each array value that needs to be moved to make room to insert)
* Move the value down 1 position in the array
* END FOR
* Insert the number in the array at pos
*END - Ins # in array in asc order
*********************************************************************/
void array_insert(int Num, int Count, int Array[])
{
//local constants
//local variables
int Pos = 0; //current position in the array
/**************** begin insert ***********************************/
//WHILE (!the end of the array && the insert position is not found)
while (Pos < Count && Num > Array[Pos])
{
//Increment pos
Pos++;
}
//END WHILE
//FOR (Each array value that needs to be moved to make room to insert)
for(int Index = Count; Index > Pos; Index--)
{
//Move the value down 1 position in the array
Array[Index] = Array[Index-1];
//END FOR
}
//Insert the number in the array at pos
Array[Pos] = Num;
}// end array_insert
/**********************************************************************
*Program Name : Display array in asc or desc order
*Author :
*Date :
*Course/Section :
*Program Description: This function is designed to display the array
* in either forward or reverse order. The function receives the
* start index and the stop index to move thru the loop. First, the
* function determines the total number of values to display by
* finding the difference between the Start and Stop indexes and then
* adding 1. Then the direction is determined (forward or reverse) so
* that the array position counter can be incremented or decremented
* by 1. Lastly, a for loop is executed to display the contents of
* the array in the correct order.
*
*BEGIN - Disp array in fwd or rev (int Start, int Stop, int Array[])
* Calc # of values to display (abs value of (Start - Stop) + 1)
* IF (display is in ascending order)
* Set array position update value to a positive 1
* ELSE //display is in descending order
* Set array position update value to a negative 1
* END IF
* Set array position to Start Index
* FOR(# of values to display)
* Display the value at array position
* Modify the array position by the array position update value
* END FOR
*END - Display array in forward or reverse
*********************************************************************/
void array_insert (int Start, int Stop, int Array[])
{
//local constants
const char ASCENDING ='A';
const char DESCENDING ='D';
//local variables
int RESULT =0
/**************** begin insert ***********************************/
//Call # of values to display
RESULT = (Start - Stop) + 1;
if (RESULT == void array_insert(int Num, int Count, int Array[])
{
//Set array position update value to poistive 1
Pos = 1;
}
else (DESCENDING)
{
//Set array position update value to negative 1
Pos = -1;
}
//end if
//Set array poistion to start
Array[Pos] = Start;
//For number of values display
for (int i = 0; i < Array[Count]; i++)
{
cout << Array[Count];
cout << endl;
}