why my program running continously and not stoping? - c++

I'm trying to make an template which is my class assignment.
I used a switch statement in the do while loop while the condition is if enter variable not equal to 16 you should terminate the program
I'vve already used break statment in every case but it isn't working
#include <iostream>
using namespace std;
int main()
{
int op;
cout << "Please enter choice between 1 to 15 For Different Operations "
<< endl;
cout << "1. Create List(create a new list(presumably empty))" << endl;
cout << "2. Insertion" << endl;
cout << "3. Deletion" << endl;
cout << "4. Update(replace the element)" << endl;
cout << "5. Start" << endl;
cout << "6. Next" << endl;
cout << "7. Back" << endl;
cout << "8. Tail" << endl;
cout << "9. Find" << endl;
cout << "10. Copy" << endl;
cout << "11. Get(display current index and element)" << endl;
cout << "12. Size / length" << endl;
cout << "13. Display list" << endl;
cout << "14. De - allocate list" << endl;
cout << "15. Exit" << endl;
cin >> op;
do {
switch (op) {
case 1:
cout << "Creating the List" << endl;
break;
case 2:
cout << "inserting... " << endl;
break;
case 3:
cout << "Deleting... " << endl;
break;
case 4:
cout << "updating... " << endl;
break;
case 5:
cout << "starting... " << endl;
break;
case 6:
cout << "next... " << endl;
break;
case 7:
cout << "back... " << endl;
break;
case 8:
cout << "Tail... " << endl;
break;
case 9:
cout << "Find... " << endl;
break;
case 10:
cout << "Copying... " << endl;
break;
case 11:
cout << "Getting... " << endl;
break;
case 12:
cout << "Size... " << endl;
break;
case 13:
cout << "Display... " << endl;
break;
case 14:
cout << "Deallocate... " << endl;
break;
case 15:
terminate;
break;
default:
cout << "Please enter the correct choice " << endl;
break;
}
} while (op != 16);
return 0;
}
i expect the the cout output in every choice user made and then stop for taking input

from your original code
cin >> op;
do {
switch (op)
so you read from cin outside the loop and never read again, reordering so you read at every loop pass will ask you again the desired operation
do {
cin >> op;
switch (op)
Additionally note that break does not break the loop it just breaks from the switch. Without the break the instructions from the next case will be executed as well in the switch.
If you want to break from the loop under some conditions you need to add a break outside of the switch statement, you can use a variable to "remember" if you should leave the loop.
However since you have an exit condition in your typed instructions why not make the loop exit
} while (op != 15);
which seems to make sense because of the
cout << "15. Exit" << endl;
line.

Related

Looping for calculators

The program will take in floating-point numbers and operators from the user and perform the required calculations, printing out the results. The result of each calculation will serve as an operand for the next calculation.
So, I am not sure if I am doing this correctly by using switch statements ? Is there a better way of doing it ? Maybe, by using a do - while loop ? I am really confused.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float firstOperand;
cout << "Enter a number: ";
cin >> firstOperand;
cout << endl;
cout << "Choose an instruction code: " << endl << endl;
cout << "1) (+) for addition. " << endl;
cout << "2) (*) for multiplication. " << endl;
cout << "3) (p) for power. " << endl;
cout << "4) (c) to clear the current result. " << endl;
cout << "5) (-) for subtraction. " << endl;
cout << "6) (/) for divison. " << endl;
cout << "7) (s) for square root. " << endl;
cout << "8) (q) to quit the program. " << endl << endl;
int choice;
cin >> choice;
cout << endl;
float secondOperand;
cout << "Enter the second number: ";
cin >> secondOperand;
cout << endl;
switch (choice)
{
case 1:
{
float resultOne = firstOperand + secondOperand;
cout << "The result of the calculation is " << resultOne << endl;
}
case 2:
{
float thirdOperand;
cout << "Enter another number ";
cin >> thirdOperand;
cout << endl;
cout << "Choose an instruction code: " << endl << endl;
cout << "1) (+) for addition. " << endl;
cout << "2) (*) for multiplication. " << endl;
cout << "3) (p) for power. " << endl;
cout << "4) (c) to clear the current result. " << endl;
cout << "5) (-) for subtraction. " << endl;
cout << "6) (/) for divison. " << endl;
cout << "7) (s) for square root. " << endl;
cout << "8) (q) to quit the program. " << endl << endl;
float resultTwo = resultOne + thirdOperand;
cout << "The result of the calculation is " << resultTwo << endl;
}
break;
}
system("pause");
return 0;
}
Try this code:
#include <iostream>
#include <math.h>
using namespace std;
int main(){
float firstOperand, secondOperand, result;
int choice, quit = 0;
cout << "Enter a number: ";
cin >> firstOperand;
cout << endl;
while (1){
cout << "The first operand is " << firstOperand << endl;
cout << "\nChoose an instruction code: " << endl;
cout << "1) (+) for addition. " << endl;
cout << "2) (*) for multiplication. " << endl;
cout << "3) (p) for power. " << endl;
cout << "4) (c) to clear the current result. " << endl;
cout << "5) (-) for subtraction. " << endl;
cout << "6) (/) for divison. " << endl;
cout << "7) (s) for square root. " << endl;
cout << "8) (q) to quit the program. " << endl << endl;
cin >> choice;
cout << endl;
if (choice == 8){
cout << "Quitting the program..." << endl;
break;
}
cout << "Enter the second number: ";
cin >> secondOperand;
cout << endl;
switch(choice){
case 1: result = firstOperand + secondOperand;
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
case 2: result = firstOperand * secondOperand;
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
case 3: result = pow(firstOperand, secondOperand);
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
case 4: result = 0;
cout << "The result has been cleared to " << result << endl;
cout << "Enter the first operand: ";
cin >> firstOperand;
cout << endl;
break;
case 5: result = firstOperand - secondOperand;
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
case 6: if(secondOperand){
result = firstOperand / secondOperand;
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
}
else{
cout << "Second operand is " << secondOperand << "Choose again!" << endl;
}
case 7: result = sqrt(secondOperand);
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
default:cout << "Invalid input. Enter again!" << endl;
break;
}
}
}
The main code is wrapped inside an infinite while loop with a quit condition. The break statement is used to exit the while loop when the user wishes to.
Note: The input for the operator is the number and not the symbol. You will have to change choice variable to char in case you want to use the symbol as the input.
Update: The following code is for character inputs.
#include <iostream>
#include <math.h>
using namespace std;
int main(){
float firstOperand, secondOperand, result;
int quit = 0;
char choice;
cout << "Enter a number: ";
cin >> firstOperand;
cout << endl;
while (1){
cout << "The first operand is " << firstOperand << endl;
cout << "\nChoose an instruction code: " << endl;
cout << "1) (+) for addition. " << endl;
cout << "2) (*) for multiplication. " << endl;
cout << "3) (p) for power. " << endl;
cout << "4) (c) to clear the current result. " << endl;
cout << "5) (-) for subtraction. " << endl;
cout << "6) (/) for divison. " << endl;
cout << "7) (s) for square root. " << endl;
cout << "8) (q) to quit the program. " << endl << endl;
cin >> choice;
cout << endl;
if (choice == 'q'){
cout << "Quitting the program..." << endl;
break;
}
cout << "Enter the second number: ";
cin >> secondOperand;
cout << endl;
switch(choice){
case '+': result = firstOperand + secondOperand;
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
case '*': result = firstOperand * secondOperand;
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
case 'p': result = pow(firstOperand, secondOperand);
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
case 'c': result = 0;
cout << "The result has been cleared to " << result << endl;
cout << "Enter the first operand: ";
cin >> firstOperand;
cout << endl;
break;
case '-': result = firstOperand - secondOperand;
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
case '/': if(secondOperand){
result = firstOperand / secondOperand;
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
}
else{
cout << "Second operand is " << secondOperand << "Choose again!" << endl;
}
case 's': result = sqrt(secondOperand);
cout << "The result of the calculation is " << result << endl;
firstOperand = result;
break;
default: cout << "Invalid input. Enter again!" << endl;
break;
}
}
}
Here is one possible version on the code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int select_operation()
{
int choice;
cout << "Choose an instruction code: " << endl << endl;
cout << "1) (+) for addition. " << endl;
cout << "2) (*) for multiplication. " << endl;
cout << "3) (p) for power. " << endl;
cout << "4) (c) to clear the current result. " << endl;
cout << "5) (-) for subtraction. " << endl;
cout << "6) (/) for divison. " << endl;
cout << "7) (s) for square root. " << endl;
cout << "8) (q) to quit the program. " << endl << endl;
cin >> choice;
cout << endl;
return choice;
}
int main()
{
float secondOperand;
float firstOperand;
float thirdOperand;
float resultOne;
int choice;
cout << "Enter a number: ";
cin >> firstOperand;
cout << endl;
choice = select_operation();
if (choice == 8)
return 0;
else if(choice == 7)
secondOperand = .5;
else{
cout << "Enter the second number: ";
cin >> secondOperand;
}
cout << endl;
while(1)
{
switch (choice) {
case 1:
resultOne = firstOperand + secondOperand;
cout << "The result of the calculation is " << resultOne << endl;
break;
case 2:
resultOne = firstOperand * secondOperand;
cout << "The result of the calculation is " << resultOne << endl;
break;
case 3:
resultOne = pow(firstOperand,secondOperand);
cout << "The result of the calculation is " << resultOne << endl;
break;
case 4:
resultOne = 0;
cout << "The result of the calculation is " << resultOne << endl;
break;
case 5:
resultOne = firstOperand - secondOperand;
cout << "The result of the calculation is " << resultOne << endl;
break;
case 6:
if(secondOperand){
resultOne = firstOperand / secondOperand;
cout << "The result of the calculation is " << resultOne << endl;
}
break;
case 7:
resultOne = pow(firstOperand,secondOperand);
cout << "The result of the calculation is " << resultOne << endl;
break;
}
choice = select_operation();
if (choice == 8)
return 0;
else if(choice == 7)
secondOperand = .5;
else{
cout << "Enter another number ";
cin >> thirdOperand;
secondOperand = thirdOperand;
}
}
cout << endl;
firstOperand = resultOne;
return 0;
}
The above code accepts two inputs at first immediately returns if it is option 8(quit the program). if the operation is square root as it is a unary operation not taking in second operand.
Reading the 3rd operand and operator is continued until it is requested to stop.

Functional Loop with user input C++

So I got an assignment to make a program that allows the user to select three favourite destinations in order. It repeats until the user decides to stop. Once the user decides to discontinue, the program then displays the total votes received for each destination according to preference by the users. One user will have three preferences and if the program repeats four times, it means four users’ preferences are recorded. Therefore a total of 12 preferences are recorded in this instance.
I have tried to limit input for the loop to work but it seems it will only work with a decision which is not necessary at the beginning of the program, which i want to remove altogether.
Also, I have tried to limit output for each of the decisions but it will only run once and then move on to the next choice. Is there any way to get a persistent entry prompt that will only continue after a valid input.
Lastly, is there any way I could improve the code by using switch/break statements instead of if/else?
Here's my code:
cout << "Do you want to go forth with this program?\nType y to confirm. The
program will exit if anything else is entered: ";
cin >> Decision;
while (Decision=="y")
{
cout << "\n\nNow please enter the code for which your destination corresponds to: " << endl; //first decision
cin >> Choice1;
if (Choice1 == 1)
{
LasVegas1++;
}
else if (Choice1 == 2)
{
Tokyo1++;
}
if (cin.fail())
{
cout << "Please enter a valid choice" << endl;
continue;
}
cout << " \nNow please enter the second code: " << endl; //second decision
cin >> Choice2;
if (Choice2 == 1)
{
LasVegas2++;
}
else if (Choice2 == 2)
{
Tokyo2++;
}
else
{
cout << "\nError! Please enter a valid code as shown above!\n";
cout << "\nNow please enter the second code: ";
cin >> Choice2;
}
cout << " \nNow please enter the third code: " << endl; //third decsion
cin >> Choice3;
if (Choice3 == 1)
{
LasVegas3++;
}
else
{
cout << "\nError! Please enter a valid code as shown above!\n";
cout << "\nNow please enter the third code: ";
cin >> Choice3;
}
cout << " \nDo you wish to select three more destinations? (Y/N): " << endl;
cin >> Decision;
}
What I would do is to put all your city variables into an array and then convert your three sets of code into a for loop. Something like:
for(int i = 0; i < 3; i++) {
if(Choice1 == 0) {
rome[i]++;
}
//etc
So that way you wouldn't need to repeat the same code three times. Also you only need one Choice variable. (You can just reset it at each iteration of the loop)
Additionally you could implement a switch statement to clean up the code a little:
switch(Choice1) {
case 1:
LasVegas1++;
break;
case 2:
Tokyo1++;
break;
case 3:
London1++;
break;
case 4:
Paris1++;
break;
case 5:
Dubai1++;
break;
case 6:
Mumbai1++;
break;
case 7:
NewYork1++;
break;
case 8:
Sydney1++;
break;
case 9:
Auckland1++;
break;
case 10:
Rome1++;
break;
case 11:
Other1++;
break;
}
It can be heavily simplified by the use of "Switch" and "Break".
Like the code that i have written. Have a look :
char input;
int choice;
void Permission() {
cout << "Do you want to go forth with this program ? (y to confirm)" << flush;
cin >> input;
cout << endl;
}
void Decision1() {
if(input == 'y') {
cout << "Now please enter the code for which your destination corresponds to : " << flush;
cin >> choice;
switch (choice) {
case 1:
cout << "LasVegas " << endl;
break;
case 2:
cout << "Tokyo " << endl;
break;
case 3:
cout << "London " << endl;
break;
case 4:
cout << "Paris " << endl;
break;
case 5:
cout << "Dubai " << endl;
break;
case 6:
cout << "Mumbai " << endl;
break;
case 7:
cout << "New York " << endl;
break;
case 8:
cout << "Sydney " << endl;
break;
case 9:
cout << "Auckland " << endl;
break;
case 10:
cout << "Rome " << endl;
break;
case 11:
cout << "Other " << endl;
break;
default:
cout << "Invalid option. Enter Again : " << flush;
cin >> choice;
}
cout << endl;
}
}
void Decision2() {
cout << "Now please enter the second code: " << flush;
cin >> choice;
switch (choice) {
case 1:
cout << "LasVegas " << endl;
break;
case 2:
cout << "Tokyo " << endl;
break;
case 3:
cout << "London " << endl;
break;
case 4:
cout << "Paris " << endl;
break;
case 5:
cout << "Dubai " << endl;
break;
case 6:
cout << "Mumbai " << endl;
break;
case 7:
cout << "New York " << endl;
break;
case 8:
cout << "Sydney " << endl;
break;
case 9:
cout << "Auckland " << endl;
break;
case 10:
cout << "Rome " << endl;
break;
case 11:
cout << "Other " << endl;
default:
cout << "Invalid option. Enter Again : " << flush;
cin >> choice;
}
cout << endl;
}
void Decision3() {
cout << "Now please enter the third code: " << flush;
cin >> choice;
switch (choice) {
case 1:
cout << "LasVegas " << endl;
break;
case 2:
cout << "Tokyo " << endl;
break;
case 3:
cout << "London " << endl;
break;
case 4:
cout << "Paris " << endl;
break;
case 5:
cout << "Dubai " << endl;
break;
case 6:
cout << "Mumbai " << endl;
break;
case 7:
cout << "New York " << endl;
case 8:
cout << "Sydney " << endl;
break;
case 9:
cout << "Auckland " << endl;
break;
case 10:
cout << "Rome " << endl;
break;
case 11:
cout << "Other " << endl;
break;
default:
cout << "Invalid option. Enter Again : " << flush;
cin >> choice;
}
cout << endl;
}
int main() {
Permission();
Decision1();
Decision2();
Decision3();
system("PAUSE");
return 0;
}
I don't know that how to get the loop at the default when the user enters the wrong option. I was able to give the "cin" once. Update this problem if you know how to.
Yes you could improve with a switch statement. Theres also something called a do while loop you should look into.

How can I use an if statement within or outside of a switch statement (C++)

I am brand new to programming and am doing coding challenges found from here http://www.cplusplus.com/forum/articles/12974/. I cannot find the answer to my specific question through google searches, this is my first time posting here so I apologize if I've broken any guidelines! I am looking at the challenge which makes a user pick a number to select their favorite beverage.
I just learned about the switch statement and i named 5 cases, not including the default. I was trying to figure out how to incorporate an if statement inside of a switch statement (if this is even possible), or maybe it's a for loop that i am looking for? I am not sure but i'm willing to learn about whatever it is. I am trying to make it so that if the user does not enter a valid case number and it goes to default. (ex: anything other than 1, 2, 3, 4, or 5) I want the user to make another attempt at entering a correct number when it hits the default case.
This is my code
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
int choice;
cout << "Choose your beverage of choice by number: " << endl;
cout << "1. Coke" << endl;
cout << "2. Dr. Pepper" << endl;
cout << "3. Sprite" << endl;
cout << "4. Iced Tea" << endl;
cout << "5. Water" << endl;
cout << '\n';
cin >> choice;
cout << '\n' << "Choice entered: " << choice << endl;
cout << '\n';
switch (choice)
{
case 1 : cout << "You have chosen Coke." << endl;
break;
case 2 : cout << "You have chosen Dr. Pepper." << endl;
break;
case 3 : cout << "You have chosen Sprite." << endl;
break;
case 4 : cout << "You have chosen Iced Tea." << endl;
break;
case 5: cout << "You have chosen Water." << endl;
break;
default:
cout << "Error. Choice Not valid. Money returned." << endl;
break;
}
system("pause");
return 0;
}
I am trying to make it so that if the user does not enter a valid case number and it goes to default. (ex: anything other than 1, 2, 3, 4, or 5) I want the user to make another attempt at entering a correct number when it hits the default case.
One way to make this happen is to put a do-while loop around the block of code that receives user input and the switch statement.
int main()
{
bool isValidChoice = true;
do
{
// Reset when the loop is run more than once.
isValidChoice = true;
int choice;
cout << "Choose your beverage of choice by number: " << endl;
cout << "1. Coke" << endl;
cout << "2. Dr. Pepper" << endl;
cout << "3. Sprite" << endl;
cout << "4. Iced Tea" << endl;
cout << "5. Water" << endl;
cout << '\n';
cin >> choice;
cout << '\n' << "Choice entered: " << choice << endl;
cout << '\n';
switch (choice)
{
case 1 :
cout << "You have chosen Coke." << endl;
break;
case 2 :
cout << "You have chosen Dr. Pepper." << endl;
break;
case 3 :
cout << "You have chosen Sprite." << endl;
break;
case 4 :
cout << "You have chosen Iced Tea." << endl;
break;
case 5:
cout << "You have chosen Water." << endl;
break;
default:
cout << "Error. Choice Not valid. Money returned." << endl;
isValidChoice = false;
break;
}
} while ( !isValidChoice );
}

C++ : Nested Switch Case

I have a for loop where when the quantity number is entered, the loop will run for the amount of quantity entered. But unfortunately the output summary only displays one output.
For example, when user enters the quantity number of 2, the loop of choosing the pizza, size and add on runs twice but the summary output in this particular line cout << sizetype << "/t" << pizzatype << "/t" << price << endl; only displays one output. Nevertheless, I want to display both of the output which has been entered by user.
Need help on this.
case 2:
cin >> quantity;
for(int i=0; i<quantity; i++)
cout << "**Pizza Favourites**" << endl;
cout << "1. Italian Aloha" << endl;
cout << "2. Vegi Lover" << endl;
cout << "3. Ocean Delite" << endl << endl;
cout << "Choose Your Pizza (Enter Integer 1-3 Only) : ";
cin >> pizza;
switch (pizza)
{
case 1:
cout << "You've ordered Italian Aloha Pizza" << endl;
pizzatype = "Italian Aloha Pizza";
break;
case 2:
cout << "You've ordered Vegi Lover Pizza" << endl;
pizzatype = "Vegi Lover Pizza";
break;
case 3:
cout << "You've ordered Ocean Delite Pizza" << endl;
pizzatype = "Ocean Delite Pizza";
break;
default:
cout << "Invalid Input" << endl;
break;
}
cout << "**Pizza Sizes**" << endl;
cout << "1. Regular (R)" << endl;
cout << "2. Large (L)" << endl;
cout << "3. X-Large (X)" << endl << endl;
cout << "Choose Your Pizza Size (Enter Integer 1-3 Only) : ";
cin >> size;
switch (size)
{
case 1:
cout << "You've Chose Regular Sized Pizza" << endl;
sizetype = "Regular";
price = newRegular;
break;
case 2:
cout << "You've Chose Large Sized Pizza" << endl;
sizetype = "Large";
price = newLarge;
break;
case 3:
cout << "You've Chose X-Large Sized Pizza" << endl;
sizetype = "X-Large";
price = newXlarge;
break;
default:
cout << "Invalid Input" << endl;
break;
}
}
cout << "**Add On**" << endl;
cout << "Do You Want To Add On Extra Cheese ? (Enter Y for Yes and N for No) : ";
cin >> yesNo;
switch (yesNo)
{
case 'Y':
cout << "More Cheese, More Fun !" << endl;
cheesePrice = newCheese;
break;
case 'N':
cout << "No Extra Cheese Required !" << endl;
cheesePrice;
break;
default:
cout << "Invalid Input" << endl;
break;
}
cout << "WONDER PIZZA" << endl;
cout << "************" << endl;
cout << sizetype << "/t" << pizzatype << "/t" << price << endl;
cout << "Extra Cheese : " << cheesePrice << endl;
total = price + cheesePrice;
cout << "Total Payment : " << total << endl;
cout << "Please Insert Your Payment : " << payment << endl;
change = payment - total;
cout << "Change" << change << endl;
break;
Yes, you can nest a switch statement inside the case of an outer switch statement.
The break on an inner case will be in the context of the inner switch.
(Does that answer your question? I wasn't sure that was your question.)

I'm not sure how to assign the values I want exactly

I need cherries, oranges, plumes, bells, melons, or bars to be randomly picked in the case statements and in a way I can then display what was chosen so I can compare them, but I'm not sure how.
For example, I was hoping when I printed slot1, slot2, and slot3, I would get the names of which case statement inside each of the three switches were chosen.
Not their numbers. (The program isn't done yet so it's quite messy right now)
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int main()
{
int slot1;
int slot2;
int slot3;
double won;
double money;
string cherries;
string oranges;
string plums;
string bells;
string melons;
string bars;
string doAgain;
do
{
cout << "We are going to be playing a slot machine game today." << endl;
cout << "Please enter the amount of money you'd like to insert into the slot machine." << endl;
cin >> money;
cout << "You put in $" << money << endl;
srand(time(0));
slot1=rand()%6+1;
slot2=rand()%6+1;
slot3=rand()%6+1;
switch (slot1)
{
case 1:
cout << cherries << endl;
case 2:
cout << oranges << endl;
break;
case 3:
cout << plums << endl;
break;
case 4:
cout << bells << endl;
break;
case 5:
cout << melons << endl;
break;
case 6:
cout << bars << endl;
}
switch (slot2)
{
case 1:
cout << melons << endl;
break;
case 2:
cout << bells << endl;
break;
case 3:
cout << bars << endl;
break;
case 4:
cout << plums << endl;
break;
case 5:
cout << oranges << endl;
break;
case 6:
cout << cherries << endl;
}
switch (slot3)
{
case 1:
cout << bars << endl;
break;
case 2:
cout << plums << endl;
break;
case 3:
cout << melons << endl;
break;
case 4:
cout << bells << endl;
break;
case 5:
cout << oranges << endl;
break;
case 6:
cout << cherries << endl;
}
cout << "The numbers you got were " << slot1 << ", " << slot2 << ", " << slot3 << endl;
cout << "Would you like to play again?" << endl;
cin >> doAgain;
if(doAgain!= "yes")
{
cout << "The total amount of money you put in the slot machine is" << money << endl;
cout << "The total amount of money you won is $" << won << endl;
}
}
while(doAgain=="yes");
return 0;
}
enter code here
You have declared strings for all the various fruits, but you don't assign any actual string values to them. ie string cherries = "cherries"
Just printing slot1 will only print an int as you have discovered. C++ doesn't know that you also want to print the name as well. You need to include your string as part of the cout statement