| | |
Switch/Break taking me for a loop
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2009
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
C++ Syntax (Toggle Plain Text)
// 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; }
•
•
Join Date: Mar 2009
Posts: 2
Reputation:
Solved Threads: 0
I appreciate it Master Danny, no cigar though. When I refer to my C++ book the syntax doesn't work out that way. But, I will take advice from a helpful person over a book anyday? Any idea why i get stuck in the
C++ Syntax (Toggle Plain Text)
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)
![]() |
Similar Threads
- taking code and changing format to function! PLEASE HELP!! (C++)
- Send data on a serial port (C++)
- Loop problem (C++)
- Fourtune Teller Project, switch statement confusion (C++)
- Trying to figure out how to change a couple string Arrays to Boolean arrays.. (Java)
- multiple update with text boxes (PHP)
- scanf discussion (C)
- A program with Menus and Loops...HELP!! (Java)
- Logic to Convert Days From 1800 to a Date (Month, Day, Year) (C++)
- special keys as inputs (Game Development)
Other Threads in the C++ Forum
- Previous Thread: TooTiredToSeeProblem
- Next Thread: Inheritence and constructors question
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game givemetehcodez google graph gui iamthwee ifstream input int java lib library lines linkedlist linker loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return sort string strings struct studio system temperature template templates test text text-file tree unix url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






