I recently had an issue with my recursive project in class. Here is the code.
Somehow it will not end the recursion making it infinite. How to I end this madness.
Code:
// Recursion.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <conio.h> #include <iostream> using namespace std; //define recursive function to get values and store in array void getInts(int myArrayParam[], int indexParam) { //recursive call if (indexParam<=2) { cout<<"Please enter whole number number "<<indexParam+1<<":"; cin>>myArrayParam[indexParam]; indexParam++; getInts(myArrayParam, indexParam; } } //define recursive function to ouput values in array void displayInts(int myArrayParam2[],int indexParam2) { if(indexParam2<=2) { cout<<"Whole number number "<<indexParam2+1<<" is "<<myArrayParam2(indexParam2)<<"."<<endl; indexParam2--; displayInts(myArrayParam2, indexParam2); } } int main() { //declare a three element int array and a variable to increment/decrement int myArray[3]; int index; //call recursive function to get values and store in array getInts(myArray, index); //set index to largest element index = 2; //call recursive function to output values in array displayInts(myArray, index); cout<<endl<<endl<<endl; cout<<"Press any key to exit "; getch() return 0; }
Comment