Im doing a program and cant figure it out

I cant figure out how to fix this, because it just keeps looping.
if anyone could help, I would much appreciate it

thank you


#include <iostream>
#include <string>

using namespace std;

// const variables for global use
const double largeDog = 30.00;
const double smallDog = 20.00;
const double cat = 15.00;
const double vetVisit = 75.00;
const double TOE_NAIL_CLIP = 8.00;
const double kennelService = 30.00;
double total = 0.0;
int bath = 0;
double TOT_KENNEL = 0.0;
//declaring arrays
int bathType[3] = {1, 2, 3};
double bathPrices[3] = {30.00 , 20.00, 15.00};

// void fnc prototypes
void displayCats();
void displayDogs();
double CAT_BATH_OPT();
double DOG_BATH_OPT();
double VET_OPT();
double KENNEL_OPT();
double NAIL_OPT();
double CALC_TOTAL();

int main ()
{
// variables

int days = 0;
int option = 0;
int petType = 0;
string petName = " ";

// get pets name and type of pet

cout << "Please enter the pets name: ";
cin >> petName;
cout << "Is this a dog (2) or a cat (1): ";
cin >> petType;

// options

if (petType == 1)
{
displayCats();
cout << "Enter 1, 2, 3 or 4: ";
cin >> option;
}

while ( option > 0 && option < 5)
{
displayCats();
cout << "Enter 1, 2, 3, 4: ";
cin >> option;

if (option == 1)
CAT_BATH_OPT();
else if (option == 2)
VET_OPT();
else if (option == 3)
KENNEL_OPT();
else if (option == 4)
total = bath + vetVisit + kennelService;
cout << "Your total is = $" << total << endl;
if (option > 1 || option < 4)
cout << "not valid" << endl;
}
// end if and while

if (petType == 2)
{
displayDogs();
cout << "Enter 1, 2, 3, 4, 5: ";
cin >> option;
}
while (option > 0 && option < 6)
{
if (option == 1)
DOG_BATH_OPT();
else if (option == 2)
VET_OPT();
else if (option == 3)
KENNEL_OPT();
else if (option == 4)
NAIL_OPT();
else if (option == 5)
{
total = bath + vetVisit + kennelService + TOE_NAIL_CLIP;
cout << "Your total is = $: " << total << endl;
}
} // end while and end if

if (option != 1 && option != 2)
cout << "Not valid" << endl;
// end if


system("pause");
return 0;
} // end of main fnc

//// ********fnc definitions********
void displayCats()
{
cout << "Bath 1" << endl;
cout << "Vet visit 2" << endl;
cout << "Kennel service 3" << endl;
cout << "Your Total Bill 4 " << endl;
}// end of displayCats

void displayDogs()
{
cout << "Bath 1" << endl;
cout << "Vet visit 2" << endl;
cout << "Kennel service 3" << endl;
cout << "Nail Clipping 4" << endl;
cout << "Your Total Bill 5" << endl;
} // end of displayDogs

double CAT_BATH_OPT()
{

int sub = 1;
bath = bathPrices[3];
total = total + bath;
return bath;

}//end of catBathOption function

double DOG_BATH_OPT()

{


cout << "Enter 1 for Large dog or 2 for Small dog: ";
cin >> bath;
if (bath == 1)
bath = bathPrices[0];

else if (bath == 2)
bath = bathPrices[1];
else if (bath < 0 && bath > 3)
cout << "Invalid" << endl;
total = total + bath;
cout << "total" << total << endl;


return bath;
//end if
}//end of DOG_BATH_OPT


double VET_OPT()
{

total = total + vetVisit;
return vetVisit;
} //end of VET_OPT

double KENNEL_OPT()
{

int days = 0;
double TOT_KENNEL = 0.0;

cout << "Enter Numer of Days in Kennel: ";
cin >> days;
TOT_KENNEL = (kennelService*days);
total = total + TOT_KENNEL;
return TOT_KENNEL;
} //end of KENNEL_OPT

double NAIL_OPT()
{
int option = 0;

total = total + TOE_NAIL_CLIP;
system("pause");
cout << "are you finished? 1 for yes and 2 for no";
cin >> option;
if (option == 1)
cout << "total " << total << endl;
else if (option == 2)
cout << "total " << total << endl;
return TOE_NAIL_CLIP;
// end if
} //end of NAIL_OPT

double CALC_TOTAL()
{
total = bath + vetVisit + TOT_KENNEL + TOE_NAIL_CLIP;
return total;
} //end calc total function
As a tip, most people on here wont go through the trouble of compiling your code. Could you tell us where it is looping?
K, it starts looping here

double DOG_BATH_OPT()

{


cout << "Enter 1 for Large dog or 2 for Small dog: ";
cin >> bath;
if (bath == 1)
bath = bathPrices[0];

else if (bath == 2)
bath = bathPrices[1];
else if (bath < 0 && bath > 3)
cout << "Invalid" << endl;
total = total + bath;
cout << "total" << total << endl;

return bath;
//end if
}//end of DOG_BATH_OPT
I think its the while loop
while (option > 0 && option < 6)
option never changes so the loop never ends calling whatever function was initially chosen
Last edited on
not sure how to end it
You dont need a loop at all. Use a switch statement or a bunch of ifs like you have
inside the loop.
Regrettably i have to use a loop, its required and i get it to the dog bath part and then it just loops the dog option over and over again.

heres the new code

#include <iostream>
#include <string>

using namespace std;

// const variables for global use
const double largeDog = 30.00;
const double smallDog = 20.00;
const double cat = 15.00;
const double vetVisit = 75.00;
const double TOE_NAIL_CLIP = 8.00;
const double kennelService = 30.00;
double total = 0.0;
int bath = 0;
double TOT_KENNEL = 0.0;
//declaring arrays
int bathType[3] = {1, 2, 3};
double bathPrices[3] = {30.00 , 20.00, 15.00};

// void fnc prototypes
void displayCats();
void displayDogs();
double CAT_BATH_OPT();
double DOG_BATH_OPT();
double VET_OPT();
double KENNEL_OPT();
double NAIL_OPT();
double CALC_TOTAL();

int main ()
{
// variables

int days = 0;
int option = 0;
int petType = 0;
string petName = " ";

// get pets name and type of pet

cout << "Please enter the pets name: ";
cin >> petName;
cout << "Is this a dog (2) or a cat (1): ";
cin >> petType;

// options

if (petType == 1)
{
displayCats();
cout << "Enter 1, 2, 3 or 4: ";
cin >> option;


while ( option > 0 && option < 5)


if (option == 1)
CAT_BATH_OPT();
else if (option == 2)
VET_OPT();
else if (option == 3)
KENNEL_OPT();
else if (option == 4)

total = bath + vetVisit + kennelService;
cout << "Your total is = $" << total << endl;

if (option > 1 || option < 4)
cout << "not valid" << endl;
}
// end if and while

if (petType == 2)
{
displayDogs();
cout << "Enter 1, 2, 3, 4, 5: ";
cin >> option;


while (option > 0 && option < 6)


if (option == 1)
DOG_BATH_OPT();
else if (option == 2)
VET_OPT();
else if (option == 3)
KENNEL_OPT();
else if (option == 4)
NAIL_OPT();
else if (option == 5)

total = bath + vetVisit + kennelService + TOE_NAIL_CLIP;
cout << "Your total is = $: " << total << endl;

} // end while and end if

if (option != 1 && option != 2)
cout << "Not valid" << endl;
// end if


system("pause");
return 0;
} // end of main fnc

//// ********fnc definitions********
void displayCats()
{
cout << "Bath 1" << endl;
cout << "Vet visit 2" << endl;
cout << "Kennel service 3" << endl;
cout << "Your Total Bill 4 " << endl;
}// end of displayCats

void displayDogs()
{
cout << "Bath 1" << endl;
cout << "Vet visit 2" << endl;
cout << "Kennel service 3" << endl;
cout << "Nail Clipping 4" << endl;
cout << "Your Total Bill 5" << endl;
} // end of displayDogs

double CAT_BATH_OPT()
{

int sub = 1;
bath = bathPrices[3];
total = total + bath;
return bath;

}//end of catBathOption function

double DOG_BATH_OPT()

{


cout << "Enter 1 for Large dog or 2 for Small dog: ";
cin >> bath;

if (bath == 1)

bath = bathPrices[0];


else if (bath == 2)

bath = bathPrices[1];


else if (bath > 0 && bath < 3)

cout << "Invalid" << endl;

total = total + bath;

cout << "total" << total << endl;


return bath;

//end if
}//end of DOG_BATH_OPT


double VET_OPT()
{

total = total + vetVisit;
return vetVisit;
} //end of VET_OPT

double KENNEL_OPT()
{

int days = 0;
double TOT_KENNEL = 0.0;

cout << "Enter Numer of Days in Kennel: ";
cin >> days;
TOT_KENNEL = (kennelService*days);
total = total + TOT_KENNEL;
return TOT_KENNEL;
} //end of KENNEL_OPT

double NAIL_OPT()
{
int option = 0;

total = total + TOE_NAIL_CLIP;
system("pause");
cout << "are you finished? 1 for yes and 2 for no";
cin >> option;
if (option == 1)
cout << "total " << total << endl;
else if (option == 2)
cout << "total " << total << endl;
return TOE_NAIL_CLIP;
// end if
} //end of NAIL_OPT

double CALC_TOTAL()
{
total = bath + vetVisit + TOT_KENNEL + TOE_NAIL_CLIP;
return total;
} //end calc total function
Change
while ( option > 0 && option < 5)
to
while(option < 1 || option > 4)
and
while (option > 0 && option < 6)
to
while(option < 1 || option > 5)

see if that helps
Topic archived. No new replies allowed.