Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I know that there is some things wrong just not sure on how to fix (i need a loo

ID: 3660225 • Letter: I

Question

I know that there is some things wrong just not sure on how to fix (i need a loop in the main that allows the user to enter data until the number 999 is encountered.) (I also need to validate the users input for the getSpeciesCode function #include #include #include #include #include using namespace std; enum SpeciesDesc { Loblolly_Pine, White_Pine, Red_Pine, White_Oak, Red_Oak, Other_Oak}; // funtion prototypes int getTreeNo(); int getSpeciesCode(); int main() { // declare var double b0[6]; double b1[6]; int speciesCode; int species[6] = {11, 12, 13, 21, 22, 23}; SpeciesDesc speciesDesc; int treeNo; treeNo = getTreeNo(); speciesCode = getSpeciesCode(); // Main loop while(treeNo < 999) { getTreeNo(); getSpeciesCode(); } system("pause"); return 0; } // getTreeNo function int getTreeNo() { int treeNo; do { cout<<"Please enter the tree number (number must be postive and not exceed 200):"<<endl; cin>>treeNo; if(treeNo < 0 || treeNo > 200 || treeNo == 999) cout<<"Invalid number try again."<<endl; }while(treeNo < 0 || treeNo == 999 || treeNo == 999); return treeNo; } int getSpeciesCode() { int speciesCode; do { cout<<"Please enter a valid species code:"<<endl; cin>>speciesCode; }while(speciesCode); return speciesCode; }

Explanation / Answer

/*100% running code-thankzs*/

#include <iostream>
#include <cstdlib>

using namespace std;
string speciesDesc[] ={ "Loblolly_Pine", "White_Pine", "Red_Pine", "White_Oak", "Red_Oak", "Other_Oak"};

int getTreeNo();
int getSpeciesCode();
int main()
{

    double b0[6];
    double b1[6];
    int speciesCode;
    int species[6] = {11, 12, 13, 21, 22, 23};
    int treeNo,i,index;
     do{
       treeNo=getTreeNo();
       if(treeNo==999)
          break;
       speciesCode = getSpeciesCode();
      for(i=0;i<6;i++)
       {
           if(speciesCode==species[i])
           {
                index=i;
                break;
           }

       }
      cout<<"Dish is :"<<speciesDesc[index];
     }while(treeNo!=999);
    system("pause");
    return 0;
}

int getTreeNo()
{
    int treeNo;
    do
    {
        cout<<" Please enter the tree number (number must be postive and not exceed 200):"<<endl;
        cin>>treeNo;
        if(treeNo==999)
           break;
        else if(treeNo < 0 || treeNo > 200)
        cout<<"Invalid number try again."<<endl;
    }while(treeNo < 0 || treeNo >200);
    return treeNo;
}
int getSpeciesCode()
{
    int speciesCode;
    do
    {
        cout<<"Please enter a valid species code:"<<endl;
        cin>>speciesCode;
    }while(speciesCode!=11 && speciesCode!=12 &&
           speciesCode!=13 && speciesCode!=21 &&
           speciesCode!=22 && speciesCode!=23);
    return speciesCode;
}