never-ending do-while loop? (or something else?)
Jul 17, 2014 at 7:59pm UTC
So I wrote this program and it's for a (fictious) company that offers multiple vacation packages and the user is supposed to choose one and answer questions to get a price quote. Anyway I have the program written but I think there's a problem with my do-while loop? Once the user enters his/her selection strings of numbers spits out in a never-ending fashion. My code is below, sorry there's a lot of it.
Is it my do-while loop or a problem elsewhere? I appreciate any help!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
#include <iomanip>
#include <iostream>
using namespace std;
//Variables:
const float climbRate = 350.0;
const float scubaRate = 1000.0;
const float skyDiveRate = 400.0;
const float caveRate = 700.0;
const float climbInstruct = 100.0;
const float scubaInstruct = 100.0;
const float dailyCampRental = 40.0;
const float dayLodge1 = 65.0; //Wilderness Lodge
const float dayLodge2 = 120.0; //Luxury Inn
int no_of_people;
float baseChargeDiscount;
void displayMenu();
float scuba();
float skyDive();
float climbing();
float spelunk();
int x;
int main ()
{
cout << "How many people are in your party?" << endl;
cin >> no_of_people;
displayMenu ();
cout << "What is your selection? " << endl;
cin >> x;
do {
switch (x)
{case 1:
cout << climbing;
break ;
case 2:
cout << scuba;
break ;
case 3:
cout << skyDive;
break ;
case 4:
cout << spelunk;
break ;
};
}
while (x != 5);
system ("pause" );
return 0;
}
void displayMenu ()
{
cout << "Please choose your vacation package." <<endl;
cout << "MENU: " <<endl;
cout << "1: Devil's Courthouse Adventure Weekend " <<endl;
cout << "camping, rock-climbing and rapelling at Devil's Courthouse, " << endl;
cout << "North Carolina. This getaway is for novices and experts alike. Optional " <<endl;
cout << "climbing equipment rental is available." << endl;
cout << "2. Scuba Bahama " << endl;
cout << "week-long cruise to the Bahamas with three days of scuba diving." <<endl;
cout << "Optional but afforable diving lessons available for beginners." << endl;
cout << "3. Sky-Dive Colorado " << endl;
cout << "Four thrilling days with expert sky-diving instructors in Colorado Springs" <<endl;
cout << "Colorado. For lodging, choose either Wilderness Lodge or Luxury Inn." <<endl;
cout << "4. Barron Cliff Spelunk " <<endl;
cout << "Eight days hikign and exploring caves in Barron Cliff Wilderness Area" << endl;
cout << " Tennessee. Camping equipment rental available." <<endl;
cout << "Note: A 10 percent discount on the base charges of any package is "
<< "given for a party of five or more." <<endl;
cout << "5. None of the above." <<endl;
;
}
float climbing ()
{
int a;
int b;
int c;
float baseCharge;
float instruction;
float rentalCharge;
float finalCost;
cout << "How many in your party need instruction?" <<endl;
cin >> a;
cout << endl;
cout << "How many advanced climbers in your party?" << endl;
cin >> b;
cout << endl;
cout << "How many people in party are renting equipment?" << endl;
cin >> c;
//base charge
if ( no_of_people >= 5)
baseCharge = 0.10 * (climbRate * no_of_people);
else
baseCharge = climbRate * no_of_people;
//cost of instruction
instruction = climbInstruct * a;
//Equipment rental
rentalCharge = (40 * c * 3);
//total charges
finalCost = baseCharge + instruction + rentalCharge;
//Display
cout << "Your final cost of this package is:" << " " <<
"$" << finalCost << endl;
return finalCost;
}
float scuba ()
{
int a;
int b;
float baseCharge;
float instruction;
float finalCost;
cout << "How many in party need instruction?" <<endl;
cin >> a;
cout << endl;
cout << "How many advanced scuba divers in your party?" << endl;
cin >> b;
cout << endl;
//base charge
if ( no_of_people >= 5)
baseCharge = 0.10 * (scubaRate * no_of_people);
else
baseCharge = scubaRate * no_of_people;
//cost of instruction
instruction = climbInstruct * a;
//total charges
finalCost = baseCharge + instruction;
//Display
cout << "Your final cost of this package is:" << " " <<
"$" << finalCost << endl;
return finalCost;
}
float skyDive ()
{
int b;
int c;
float baseCharge;
float lodgeCharge;
float finalCost;
//base charge
if ( no_of_people >= 5)
baseCharge = 0.10 * (skyDiveRate * no_of_people);
else
baseCharge = skyDiveRate * no_of_people;
cout << "How many in party are staying at Wilderness lodge?" << endl;
cin >> b;
cout << "How many in party are staying at Luxury Inn?" << endl;
cin >> c;
//lodging charges
lodgeCharge = (dayLodge1 * b) + (dayLodge2 * c);
//total charges
finalCost = lodgeCharge + baseCharge;
//Display
cout << "Your final cost of this package is:" << " " <<
"$" << finalCost << endl;
return finalCost;
}
float spelunk ()
{
int a;
float rental = 40;
float baseCharge;
float rentalCharge;
float finalCost;
cout << "How many people in party are renting equipment." << endl;
cin >> a;
//base charge
if ( no_of_people >= 5)
baseCharge = 0.10 * (caveRate * no_of_people);
else
baseCharge = caveRate * no_of_people;
//Equipment rental
rentalCharge = rental * a * 8;
//total charges
finalCost= rentalCharge + baseCharge;
//Display
cout << "Your final cost of this package is:" << " " <<
"$" << finalCost << endl;
return (finalCost);
}
Jul 17, 2014 at 8:14pm UTC
You don't provide a way for 'x' to change, so as long as the user does not type in '5', that do...while will never end.
Jul 18, 2014 at 6:33pm UTC
thank you for your help!
Topic archived. No new replies allowed.