Make this code better

Help Me Out? :)

Creating an input and output and importing a txt file.

project.cpp
#include <iostream> #include <string> #include <fstream> using namespace std; const int SIZE = 20; int main() { string groceryname; string foodnames[SIZE]; double costs[SIZE]; char tax[SIZE]; bool isPrime(int); double total = 0 { system("pause"); return 0; } int n; cout << "Groccery Program" << endl; ifstream infile; string filename; int successCode; cout << "Please enter the input file grocery name"; cin >> groceryname; ifstream inputfile(groceryname); inputfile.open(groceryname); if (infile) { for (int i = 0; i < SIZE; i++) infile >> foodnames[i] >> costs[i] >> tax[i]; infile.close(); successCode = 0; } else { cout << "There was an error in opening the file \n"; successCode = -1; } cout << "Please select your item by entering the code for the item." << endl; while (input != 1) { cout << "You are allowed to pick the same item more than once."; cout << "Enter -1 when completed"; cin >> input; if (input == -1) if (tax[input] == 1 { taxable[=numOrdrs] = input; nontaxable[numOrdrs] = -1 if (tax[input] == 'T') { cout << itemnames[input] << setw(6) << costs[input] << " "; } else { taxable[numOrdrs] = -1; nontaxable[numOrdrs] = input; } numOrdrs++; } for (int i = 0; i < numOrdrs; ++1) { if (taxable[numOrdrs] != -1) { totalPrice += costs[taxable[i]]; totalTax += costs[taxable[i]] = 0.15; } else if (nontaxable[numOrdrs] != -1) { totPrice += costs[nontaxable[i]]; totPrice += totTax; } } cout << "The amount on the tax is $" << toTax << "\n"; cout << "Your balance is $" << toPrice << "\n"; cout << "Thank you, your order has been completed \n"; ofstream outFile(outputFile); ofstream outFile(outputFile); if (outFile.is_open()) { outFile << "The Grocery Recipt"; for (int i = 0; i < numOrdrs; i++) { if (nontaxable[i] != -1) { outFile << foodnames[nontaxable[i]] << costs[nontaxable[i]]; } } for (int i = 0; i < numOrdrs; i++) { if (taxable[i] != 1) { outFile << foodnames[taxable[i]] << costs[taxab; e[i]] << "Taxable items"; } } outFile << "Amount on the tax is $" << endl; outFile << "The total amount on your balance is $" << endl; outFile << "Your online order has been proccessed, thank you" << endl; } if { cout << "The file cannot be opened" << endl; return 0; } outFile.close(); { } system("pause"); return 0;

Reactions 0 reactions

No reactions yet, be the first: comment or tweak the code

Comment on this code:

Please Login or Register to leave a comment.