Hello, I am reaally green to C++
1. I am trying to create a code that calculates and then produces a small invoice.
Input: Company Name
Input: Account Number
Input: Opening Balance
Input: Account Type:
I=invoiceReceived P=invoicePayment #endTransaction
Input: Amount Invoiced
Input: Amount Paid
If someone with experience were to see the code it would probably be easy, but I cannot say I am quite there yet.
2. My code is always resulting in a syntax error:'break' 2059. Line 114
3. I would like my code to produce an invoice displaying only the companyName, accountNum, and the endingBalance,
however it gets stuck in athe loop i constructed not allowing me to get further than I,P, or # selection.
4. There are no contents of any input files, all data can be made up on the spot.
// program_id APAccounts.cpp
// written_by matt schwartz
// date_written 3/22/2009
// description This program will get account transactions and return
// account balances and the sum of account balances.
//
// #include <fstream>
// #include<conio.h>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
#define clearScreen() {for(int i=0; i<=25; ++i) {cout << endl; cout << flush;}}
// functions
char moreTrans(); // Asks if there are more transactions
void getAccountInfo(); // function gets company name and account number, stores results global variable
double displayAccountSummary(double openBalance); // does the math and returns the closing balance
double transaction(); // function to get the transaction info into an array
double sumArray(const double list[], int listSize); // function that will sum an array
// global variables
int invoiceArraySize = 0;
int paymentArraySize = 0;
double beginBalance = 0;
double invoice[20] = {0}; // arrays for storing the info we need
double payment[20] = {0}; // to process
double accountTotals[40] = {0};
string companyName; // suppliers company name
string accountNum; // Little shops account number with this company
int main()
{
char flag = 'Y'; // loop control variable, exit when the user says
// there are no more accounts to enter.
int counter = 0; // array element counter, # of accounts processed
double totalPayable = 0;
while (flag != 'N') // enter loop
{
getAccountInfo(); // calling a function, Asks for company name and account number and stores
accountTotals[counter] = transaction(); // calling a function, gets the details of account
// transaction returns the ending balance of thr current account ending balance of each account is an array element
counter = counter++;
displayAccountSummary(beginBalance);
cout << "Would you like to enter more accounts?(Y/N)" << endl;
cin >> flag;
}
totalPayable = sumArray(accountTotals, counter);
cout << fixed << showpoint;
cout << setprecision(2);
// cout<< "The sum of the open Accounts payable is $" << sumArray(accountTotals, counter) << endl;
// cout<< "The sum of the open Accounts payable is $" << totalPayable << endl;
return 0;
}
void getAccountInfo() // function gets company name and
{ // account info and stores them in
cout << " Please enter the Company Name "; // global variables.
cout << endl;
cin >> companyName;
cout << " Please enter the account number ";
cout << endl;
cin >> accountNum;
}
double transaction()
{
double transAmount = 0;
char transactionType = 'I';
clearScreen();
cout << endl << endl << endl << endl << endl << " Suppliers company name " << companyName << endl;
cout << "Please enter the account opening balance. ";
cout << endl;
cin >> beginBalance;
while ( transactionType != '#') // enter loop
{
cout << "Please enter a transaction type ";
cout << endl;
cout << "I = invoice ";
cout << endl;
cout << "P = Payment ";
cout << endl;
cout << "# = no more transactions ";
cout << endl;
cout << "(I/P/#) ? ";
cout << endl;
cin >> transactionType;
switch (transactionType)
{ // enter switch
case 'I':
case 'i':
invoice[invoiceArraySize] = transAmount; // transaction is a debit, store the amount in the invoice array
invoiceArraySize++;
// transactionType = '#';
break;
case 'P':
case 'p':
payment[paymentArraySize] = transAmount; // transaction is a credit, store the amount in the payment array
paymentArraySize++;
// transactionType = '#';
break;
case '#':
if
break;
default:
cout << "Invalid response, please try again. I, P, or # ";
cout << endl;
cin >> transactionType;
}
// exit switch
}
// exit loop
return beginBalance;
}
double sumArray(const double list[], int listSize) // function that will sum an array
{ // returns a sum
int index;
double sum = 0;
for (index = 0; index < listSize; index++)
sum =sum + list[index];
return sum;
}
char moreTrans() // function will ask if there
{ // are more transactions to
char resp; // procees and returns the
// response
cout << "Would you like to enter more transactions?(Y/N)" << endl;
cin >> resp;
return resp;
}
double displayAccountSummary(double beginBalance)
{
double closingBalance;
cout << "The sum of the payments is $" << sumArray(payment, paymentArraySize);
cout << endl;
cout << "The sum of the invoices is $" << sumArray(invoice, invoiceArraySize);
cout << endl;
cout << "The opening Balance is $" << beginBalance;
cout << "The closing Balance is $" << (beginBalance + sumArray(invoice, invoiceArraySize) - sumArray(payment, paymentArraySize));
closingBalance = (beginBalance + sumArray(invoice, invoiceArraySize) - sumArray(payment, paymentArraySize));
return closingBalance;
}