C++ : Nested Switch Case - c++

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.)

Related

Vending Machine C++ - Error in while loop

I am writing a "vending machine/grocery shopping" code in C++ where I have a menu of 5 items and the user can choose to add as my items as they want. The price is calculated at the end.
Since the user can add as many items they want, I used a while loop to so they can "continue shopping." However, I was not able to successfully do this because they code would keep running. I tried to put the switch statement in a function but did not call the "reply" properly.
Could someone help me with this code, specifically the while loop and switch statement function called int shoppingCart(). If someone could help me with abstracting this code that would be great!)
Code below (this is the original, I put an edited one below):
#include <iostream>
using namespace std;
void vendingMachine() {
cout << "1. Popcorn: $2" << endl;
cout << "2. Coconut Clusters: $3" << endl;
cout << "3. Granola Bar: $2.50" << endl;
cout << "4. Trail Mix: $1.50" << endl;
cout << "5. Chocolate: $1" << endl;
cout << "Press 0 to checkout" << endl;
}
int main() {
cout << "Vending Machine" << endl;
cout << "----Items------" << endl;
vendingMachine();
cout << "Enter you selection: " << flush;
int input;
cin >> input;
float cost;
switch (input) {
case 1:
cout << "You added Popcorn to your cart." << endl;
cost = 2;
break;
case 2:
cout << "You added Coconut Clusters to your cart." << endl;
cost = 3;
break;
case 3:
cout << "You added Granola Bar to your cart." << endl;
cost = 2.50;
break;
case 4:
cout << "You added Trail Mix to your cart." << endl;
cost = 1.50;
break;
case 5:
cout << "You added Chocolate to your cart." << endl;
cost = 1;
break;
case 6:
cout << "Checkout" << endl;
break;
default:
cout << "Please select an item from the menu" << endl;
}
cout << "Continue shopping (y/n): " << flush;
string reply;
cin >> reply;
while(reply == "y") {
cout << "Enter your selection: " << flush;
int input;
cin >> input;
float cost;
switch (input) {
case 1:
cout << "You added Popcorn to your cart." << endl;
cost = 2;
break;
case 2:
cout << "You added Coconut Clusters to your cart." << endl;
cost = 3;
break;
case 3:
cout << "You added Granola Bar to your cart." << endl;
cost = 2.50;
break;
case 4:
cout << "You added Trail Mix to your cart." << endl;
cost = 1.50;
break;
case 5:
cout << "You added Chocolate to your cart." << endl;
cost = 1;
break;
case 6:
cout << "Checkout" << endl;
break;
default:
cout << "Please select an item from the menu" << endl;
}
cout << "Continue shopping (y/n): " << flush;
string reply;
cin >> reply;
break;
}
cout << "Proceding to checkout..." << endl;
cout << "Pay amount: $" << flush;
float money;
cin >> money;
if (money > cost) {
float change = money-cost;
cout << "Thank you! You have $" << change << " change." << endl;
}
if (money == cost) {
cout << "Thank you! Have a nice day!." << endl;
}
if (money < cost) {
float amountOwed = cost-money;
cout << "Please insert another $" << amountOwed << endl;
cout << "Enter amount: " << flush;
float payment;
cin >> payment;
if (payment > amountOwed) {
float change2 = payment-cost;
cout << "Thank you! You have $" << change2 << " change." << endl;
}
if (payment == amountOwed) {
cout << "Thank you! Have a nice day!." << endl;
}
if (payment < amountOwed) {
cout << "Sorry, you did not enter enough money. Your cart has emptied." << endl;
}
}
return 0;
}
Edited code:
#include <iostream>
using namespace std;
void vendingMachine() {
cout << "1. Popcorn: $2" << endl;
cout << "2. Coconut Clusters: $3" << endl;
cout << "3. Granola Bar: $2.50" << endl;
cout << "4. Trail Mix: $1.50" << endl;
cout << "5. Chocolate: $1" << endl;
cout << "Press 0 to checkout" << endl;
}
int processSelection() {
cout << "Enter your selection: " << flush;
int input;
cin >> input;
return input;
}
int shoppingCart() {
int selection = processSelection();
float cost;
switch (selection) {
case 1:
cout << "You added Popcorn to your cart." << endl;
cost = 2;
break;
case 2:
cout << "You added Coconut Clusters to your cart." << endl;
cost = 3;
break;
case 3:
cout << "You added Granola Bar to your cart." << endl;
cost = 2.50;
break;
case 4:
cout << "You added Trail Mix to your cart." << endl;
cost = 1.50;
break;
case 5:
cout << "You added Chocolate to your cart." << endl;
cost = 1;
break;
case 6:
cout << "Checkout" << endl;
break;
default:
cout << "Please select an item from the menu" << endl;
}
cout << "Continue shopping (y/n): " << flush;
string reply;
cin >> reply;
return reply;
}
int main() {
cout << "Vending Machine" << endl;
cout << "----Items------" << endl;
vendingMachine();
int reply = shoppingCart();
float cost;
while(reply == "y") {
processSelection();
shoppingCart();
}
cout << "Proceding to checkout..." << endl;
cout << "Pay amount: $" << flush;
float money;
cin >> money;
if (money > cost) {
float change = money-cost;
cout << "Thank you! You have $" << change << " change." << endl;
}
if (money == cost) {
cout << "Thank you! Have a nice day!." << endl;
}
if (money < cost) {
float amountOwed = cost-money;
cout << "Please insert another $" << amountOwed << endl;
cout << "Enter amount: " << flush;
float payment;
cin >> payment;
if (payment > amountOwed) {
float change2 = payment-cost;
cout << "Thank you! You have $" << change2 << " change." << endl;
}
if (payment == amountOwed) {
cout << "Thank you! Have a nice day!." << endl;
}
if (payment < amountOwed) {
cout << "Sorry, you did not enter enough money. Your cart has emptied." << endl;
}
}
return 0;
}
It looks like you're making great progress learning to code. Some thoughts:
Abstract duplicate code. Your switch statement is identical in two places. That makes it easy for bugs to appear! For example, if the price of one item changes, you might forget to update it in one place but not the other, which could lead to tricky bugs.
You have a break statement at the end of the while loop. Do you want to break on every iteration? Probably not. When do you want to break out of the loop? Under what conditions do you not want to continue? Think about the control flow, and how while loops work. While some condition is true, continue looping. Once it's false, stop looping. What is that condition? Is it just reply == y? That works on the first iteration, what about other iterations?
Some of you if statements say things like "have a good day." That sounds like a good time to break out of the loop to me. What do you think?

why my program running continously and not stoping?

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.

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.

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 );
}

How to change the program to enter the data with spaces while using fstream

void Motherboards::add()
{
char x;
int X;
fstream InFileMB("Motherboard_List.txt", ios::in | ios::out | ios::app);
if (!InFileMB)
{
cerr << "Error: Opening File Failed !!";
}
else
{
MotherBoardEntry:
system("cls");
cout << " Enter the name of the Manufacturer :\n";
string MB__Name_Manufacturer;
cin >> MB__Name_Manufacturer;
cout << " Enter Chipset Type :\n";
string MB_Chip;
cin >> MB_Chip;
cout << "Enter Name of the board exactly as it`s written on the box :\n";
string MB_Name;
cin >> MB_Name;
cout << "Enter 3 features of this board :\n";
cout << "1.) ";
string MB_Feature1;
cin >> MB_Feature1;
cout << endl;
cout << "2.) ";
string MB_Feature2;
cin >> MB_Feature2;
cout << endl;
cout << "3.) ";
string MB_Feature3;
cin >> MB_Feature3;
cout << endl;
cout << "Enter Price :\n";
string MB_Price;
cin >> MB_Price;
system("cls");
cout << "Please check the details before conformation :\n";
cout << "Motherboard :\n";
cout << MB__Name_Manufacturer << endl;
cout << MB_Chip << endl;
cout << MB_Name << endl;
cout << "Features :\n";
cout << "1.) " << MB_Feature1 << endl;
cout << "2.) " << MB_Feature2 << endl;
cout << "3.) " << MB_Feature3 << endl;
cout << "Price :\n";
cout << MB_Price;
cout << "\n\n Do You Want To Add The Following Motherboard To Your Stock List ? (y/n)";
cin >> x;
system("cls");
switch (x)
{
case 'y':
InFileMB << "Motherboard :\n" << MB__Name_Manufacturer << endl << MB_Chip << endl << MB_Name << endl << "Price :\n" << MB_Price << endl << "Features :\n" << "1.) " << MB_Feature1 << endl << "2.) " << MB_Feature2 << endl << "3.) " << MB_Feature3 << endl << endl;
break;
case 'Y':
InFileMB << "Motherboard :\n" << MB__Name_Manufacturer << endl << MB_Chip << endl << MB_Name << endl << "Price :\n" << MB_Price << endl << "Features :\n" << "1.) " << MB_Feature1 << endl << "2.) " << MB_Feature2 << endl << "3.) " << MB_Feature3 << endl << endl;
break;
case 'n':
system("cls");
system("pause,2");
cout << " Enter ( 1 ) to try to enter the data again or ( 2 ) to go back to item selection list .. ";
cin >> X;
switch (X)
{
case 1:
goto MotherBoardEntry;
break;
case 2:
break;
}
break;
case 'N':
system("cls");
system("pause,2");
cout << " Enter ( 1 ) to try enter the data again or ( 2 ) to go back to item selection list .. ";
cin >> X;
switch (X)
{
case 1:
goto MotherBoardEntry;
break;
case 2:
break;
}
break;
}
}
}
When I input the data as I am going to show in the snapshots that I provide when I enter the data without any spaces all goes well but when i do enter the data with spaces i cant fill out certain data due to some reason that I don't know as I am a beginner. Can you please tell me exactly where to update and what to update.
[enter image description here][1]
[enter image description here][2]
As you may have noticed in the picture where i have put a space between i7 and 4790k i couldn`t fill out the information for entering the name of the processor and the command window shifted me directly to the next line.