Hello...questions are below :)
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
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Declare variables.
string addIn; // Add-in ordered
string XXX;
const int NUM_ITEMS = 5; // Named constant
// Initialized array of add-ins
string addIns[5] = {"Cream", "Cinnamon", "Chocolate", "Amaretto", "Whiskey"};
// Initialized array of add-in prices
double addInPrices[5] = {.89, .25, .59, 1.50, 1.75};
bool foundIt = false; // Flag variable
int x; // Loop control variable
double orderTotal = 2.00; // All orders start with a 2.00 charge
// Get user input
cout << "Enter coffee add-in or XXX to quit: ";
cin >> addIn;
// Write the rest of the program here.
for(x = 0; x < NUM_ITEMS; x++)
{
cout << addIns[x] << " cost " << addInPrices[x] << ", "<< "Order Total is " << addInPrices[x] + orderTotal + 1.75 << endl;
cout << "Additional Charge: 1.75, " << endl;
}
if (addIn == addIns[x])
{
foundIt = true;
}
else
{
cout << "Sorry, we do not carry that.";
}
if (foundIt == true)
{
cout << "valid flavors" << endl;
}
else
{
cout << "invalid flavors" << endl;
}
return 0;
} // End of main()
|
My output:
Enter coffee add-in or XXX to quit: Cream
Cream cost 0.89, Order Total is 4.64
Additional Charge: 1.75,
Cinnamon cost 0.25, Order Total is 4
Additional Charge: 1.75,
Chocolate cost 0.59, Order Total is 4.34
Additional Charge: 1.75,
Amaretto cost 1.5, Order Total is 5.25
Additional Charge: 1.75,
Whiskey cost 1.75, Order Total is 5.5
Additional Charge: 1.75,
Sorry, we do not carry that. invalid flavors ===> for this statement...I want this to only show when the user enters other than the valid array data. how?
Also, is it possible just to have this kind output whenever the users enter a valid addin?
like....
output:
Enter coffee add-in or XXX to quit: Cream
Cream cost 0.89, Order Total is 4.64
Additional Charge: 1.75
or
output:
Enter coffee add-in or XXX to quit: XXX
"Thanks for using our services."
I'm kind of having trouble when comes to creating loops. Please help me learn and overcome this obstacle :D