what is wrong with this code? I need the code to accept from 0 to 100 items Plea
ID: 666812 • Letter: W
Question
what is wrong with this code? I need the code to accept from 0 to 100 items Please don't answer with wrong codes #include<iostream> #include<iomanip> #include<string> using namespace std; int main() { const int size = 100; string item[size]; double price[size], subtotal = 0; cout << "Enter the item and price" << endl; for (int counter = 0; counter < size; counter++) { cout << "Item: " << (counter + 1); cin >> item[counter]; cout << "price" << (counter + 1); cin >> price[counter]; } cout << "Here are the items:" << endl; cout << fixed << showpoint << setprecision(2); for (int counter = 0; counter < size; counter++) { double subtotal = price[counter]; cout << "subtotal:" << subtotal << endl; } system("pause"); return 0; }
Explanation / Answer
#include #include #include #define MAX_SIZE 100 // declare our struct struct Item { std::string name; double price; int quantity; }; // array of structs Item shoppingCart[MAX_SIZE]; // total items in cart int cartSize = 0; // asks user for item details and returns Item void addItem (Item cart[], int &size) { // variables to put the input into std::string name; double price = -1.0; int quantity = -1; // get item name // anything goes std::cout price; std::cin.ignore(1000, ' '); } while (price quantity; std::cin.ignore(1000, ' '); } while (quantityRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.