Я новичок в кодировании, посмотрел много учебников и купил книгу на c ++, и я программирую через Microsoft Visual Studio 2019. Я пытаюсь создать программу магазина для игрового сеанса, который я запускаю, но у менянесколько проблем с этим.1. В Visual Studio каждый раз, когда я меняю что-то, он говорит, что «cin» и «cout» означают неоднозначность и повсюду выбрасывают ошибки.2. Мой дозорный цикл не будет работать должным образом.3. Когда я захожу в меню программы, она застревает в них.
Пожалуйста, любой совет будет отличным.Действительно желая сделать это до игры этой недели.
Когда я пытаюсь что-то изменить, а затем снова запустить свой код, он будет запускаться так, как будто я ничего не изменил.
...........................................................................
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
//declare variables and file stream
ofstream outData;
string name;
char cont;
int selection;
int itemChoice;
int itemCount=0;
int price;
int quantity = 0;
double averageItem, averageTotal;
int howMany;
int total = 0;
int itemTotal;
//open the output file.
outData.open("WWWW-Invoice.dat");
//Greet the customer.
cout << "Welcome to Wild Widgets Wonderous Warehouse.\n";
cout << "Take a look around and find something that catches your eye.\n" << endl;
//get the name of the customer.
cout << "First I must ask. What is your name? ";
cin >> name;
cout << endl;
//Start the header of the invoice
outData << " Wild Widget's Wonderous Warehouse\n Invoice of services for: " << name << endl;
outData << "item" << setfill(" ") << left << setw(25) << "quantity" << setw(10) << "Price Per" << setw(10) << "Total" << endl;
outData << setfill("_") << setw(45) << endl;
//Start the selection for the character of the loop.
cout << "Well " << name << " are you ready to place your order?\nEnter y or Y to continue. ";
cin >> cont;
cout << endl;
cin.get(cont);
while ((cont == 'y') && (cont == 'Y'))
{
cout << "What you would you like to buy today? \n"
<< "1. Gear \n"
<< "2. Tools \n"
<< "3. Magic Items \n"
<< "4. Leave \n";
cin >> selection;
cout << endl;
if (selection < 1 && selection > 4)
{
cout << "Ivalid choice. \n"
<<"What you would you like to buy today? \n"
<<"1. Gear \n"
<<"2. Tools \n"
<<"3. Magic Items \n"
<< "4. Leave \n";
cin >> selection;
cout << endl;
}
while (selection != 4)
{
if (selection == 1)
{
cout << "Gear: \n"
<< "1. Glass Bottle \n"
<< "2. Component Pouch \n"
<< "3. Flask \n"
<< "4. Healer's Kit \n"
<< "5. Jug \n"
<< "6. Vial \n"
<< "7. Basic Poison \n"
<< "8. Oil Flask \n"
<< "9. Potion of Healing \n"
<< "0. Back to main \n"
<< endl;
cin >> itemChoice;
if (itemChoice < 0 || itemChoice > 9)
{
cout << "Invalid item choice. Please try again. \n"
<< "Gear: \n"
<< "1. Glass Bottle \n"
<< "2. Component Pouch \n"
<< "3. Flask \n"
<< "4. Healer's Kit \n"
<< "5. Jug \n"
<< "6. Vial \n"
<< "7. Basic Poison \n"
<< "8. Oil Flask \n"
<< "9. Potion of Healing \n"
<< endl;
cin >> itemChoice;
}
if (itemChoice == 1)
{
price = 2;
cout << "How many Glass Bottles do you want to purchase? ";
cin >> howMany;
cout << endl;
quantity += howMany;
itemTotal = price * howMany;
if (howMany > 0)
{
outData << left << setw(25) << "Glass Bottles " << setfill('_') << right <<setw(10)<< howMany <<right
<< setw(10) << right << price << setw(10) << right << itemTotal << endl;
itemCount += 1;
total += itemTotal;
}
}
else if (itemChoice == 2)
{
price = 25;
cout << "How many Component Pouches do you want to purchase? ";
cin >> howMany;
cout << endl;
quantity += howMany;
itemTotal = price * howMany;
if (howMany > 0)
{
outData << "Component Pouches " << howMany << " " << price << " " << itemTotal << endl;
itemCount += 1;
total += itemTotal;
}
}
else if (itemChoice == 3)
{
price = 1;
cout << "How many Flasks do you want to purchase? ";
cin >> howMany;
cout << endl;
quantity += howMany;
itemTotal = price * howMany;
if (howMany > 0)
{
outData << "Flasks " << howMany << " " << price << " " << itemTotal << endl;
itemCount += 1;
total += itemTotal;
}
}
else if (itemChoice == 4)
{
price = 5;
cout << "How many Healer's Kit do you want to purchase? ";
cin >> howMany;
cout << endl;
quantity += howMany;
itemTotal = price * howMany;
if (howMany > 0)
{
outData << "Healer's Kit " << howMany << " " << price << " " << itemTotal << endl;
itemCount += 1;
total += itemTotal;
}
}
else if (itemChoice == 5)
{
price = 1;
cout << "How many Jugs do you want to purchase? ";
cin >> howMany;
cout << endl;
quantity += howMany;
itemTotal = price * howMany;
if (howMany > 0)
{
outData << "Jugs " << howMany << " " << price << " " << itemTotal << endl;
itemCount += 1;
total += itemTotal;
}
}
else if (itemChoice == 6)
{
price = 2;
cout << "How many Vials do you want to purchase? ";
cin >> howMany;
cout << endl;
quantity += howMany;
itemTotal = price * howMany;
if (howMany > 0)
{
outData << "Vials " << howMany << " " << price << " " << itemTotal << endl;
itemCount += 1;
total += itemTotal;
}
}
else if (itemChoice == 7)
{
price = 100;
cout << "How many Basic Poison do you want to purchase? ";
cin >> howMany;
cout << endl;
quantity += howMany;
itemTotal = price * howMany;
if (howMany > 0)
{
outData << "Glass Bottle " << howMany << " " << price << " " << itemTotal << endl;
itemCount += 1;
total += itemTotal;
}
}
else if (itemChoice == 8)
{
price = 5;
cout << "How many Oil Flasks do you want to purchase? ";
cin >> howMany;
cout << endl;
quantity += howMany;
itemTotal = price * howMany;
if (howMany > 0)
{
outData << "Oil Flasks " << howMany << " " << price << " " << itemTotal << endl;
itemCount += 1;
total += itemTotal;
}
}
else if (itemChoice == 9)
{
price = 50;
cout << "How many Potions of Healing do you want to purchase? ";
cin >> howMany;
cout << endl;
quantity += howMany;
itemTotal = price * howMany;
if (howMany > 0)
{
outData << "Potions of Healing " << howMany << " " << price << " " << itemTotal << endl;
itemCount += 1;
total += itemTotal;
}
}
else if (itemChoice == 0)
{
cout << "What you would you like to buy today? \n"
<< "1. Gear \n"
<< "2. Tools \n"
<< "3. Magic Items \n"
<< "4. Leave \n"
<< "5. Rob the shop. \n";
cin >> selection;
cout << endl;
if (selection < 1 || selection > 5)
{
cout << "Ivalid choice. \n"
<< "What you would you like to buy today? \n"
<< "1. Gear \n"
<< "2. Tools \n"
<< "3. Magic Items \n"
<< "4. Leave \n"
<< "5. Rob the shop. \n";
cin >> selection;
cout << endl;
}
}
cout << "Gear: \n"
<< "1. Glass Bottle \n"
<< "2. Component Pouch \n"
<< "3. Flask \n"
<< "4. Healer's Kit \n"
<< "5. Jug \n"
<< "6. Vial \n"
<< "7. Basic Poison \n"
<< "8. Oil Flask \n"
<< "9. Potion of Healing \n"
<< "0. Back to main \n"
<< endl;
cin >> itemChoice;
cout << endl;
if (itemChoice < 0 || itemChoice > 9)
{
cout << "Invalid item choice. Please try again. \n"
<< "Gear: \n"
<< "1. Glass Bottle \n"
<< "2. Component Pouch \n"
<< "3. Flask \n"
<< "4. Healer's Kit \n"
<< "5. Jug \n"
<< "6. Vial \n"
<< "7. Basic Poison \n"
<< "8. Oil Flask \n"
<< "9. Potion of Healing \n"
<< endl;
cin >> itemChoice;
}
}
}
cout << "Would you like to continue. \nEnter any key except 'y' to continue. ";
cin >> cont;
cout << endl;
}
averageItem = (double)quantity / (double)itemCount;
averageTotal = (double)total / (double)itemCount;
outData << "----------------------------------------------------------------------" << endl;
outData << "Total " << quantity << " " << total << endl;
outData << "Average " << averageItem << " " << averageTotal << endl;
outData.close();
cout << "Thank You. Come back soon";
system ("pause");
return 0;
}
..........................................................................