GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 14-Oct-2006, 15:53
alfie27 alfie27 is offline
New Member
 
Join Date: Oct 2006
Posts: 12
alfie27 is on a distinguished road

i need urgent help with arrays!!


Hi,
This is what the output to the screen should look like. My code so far is below it.I'm really stuck right now and don't know what to do. Can someone please help me!!
Thanks

Point of Sale Terminal
-----------------

1. Record a Transaction
2. Transaction History

0. Exit Program

Please enter your selection: 2
Transaction History
-------------------


--------------------------------
Total payments: $0
Total refunds: $0
Ending balance: $0
--------------------------------

1. Record a Transaction
2. Transaction History

0. Exit Program

Please enter your selection: 1

Please enter the amount of the transaction
(payments as positive, refunds as negative): 50
Please enter a one-word description: shirt
Transaction recorded for shirt.

1. Record a Transaction
2. Transaction History

0. Exit Program

Please enter your selection: 1

Please enter the amount of the transaction
(payments as positive, refunds as negative): 75
Please enter a one-word description: sweater
Transaction recorded for sweater.

1. Record a Transaction
2. Transaction History

0. Exit Program

Please enter your selection: 1

Please enter the amount of the transaction
(payments as positive, refunds as negative): -35
Please enter a one-word description: belt
Transaction recorded for belt.

1. Record a Transaction
2. Transaction History

0. Exit Program

Please enter your selection: 1

Please enter the amount of the transaction
(payments as positive, refunds as negative): 100
Please enter a one-word description: jacket
Transaction recorded for jacket.

1. Record a Transaction
2. Transaction History

0. Exit Program

Please enter your selection: 1

Please enter the amount of the transaction
(payments as positive, refunds as negative): -45
Please enter a one-word description: shoes
Transaction recorded for shoes.

1. Record a Transaction
2. Transaction History

0. Exit Program

Please enter your selection: 2
Transaction History
-------------------

1. Payment: $50 - shirt
2. Payment: $75 - sweater
3. Refund: $35 - belt
4. Payment: $100 - jacket
5. Refund: $45 - shoes

--------------------------------
Total payments: $225
Total refunds: $80
Ending balance: $145
--------------------------------

1. Record a Transaction
2. Transaction History

0. Exit Program

Please enter your selection: 0
Closing Account...


*** End of Program ***

CPP / C++ / C Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int display_menu ();
int transact ();
int transaction_history ();


void main ()
{
	int menu_choice = 0,
		running_total,
		history,
		sales=1,
		refunds=1,
		current_total=1;
	char clothes [15];
		
    const int ARRAYSIZE = 25;
	int transaction [ARRAYSIZE] = {0};
	int total = 0;

	for (int i = 0; i < ARRAYSIZE; i++ )
		total += transaction[i];

cout << "Point of Sale Terminal\n"
     << "----------------------\n";

while ( menu_choice = display_menu() )
	{
	switch ( menu_choice ) {

		case 0:
			break;
		case 1:
			running_total = transact ();
				
			cout << "Please enter a one-word description: ";
			cin >> clothes;
			cout << "Transaction recorded for " << clothes << ".\n";
			break;
		case 2:
			cout << "The total is " << total << ".\n";
			break;
	}
	}
cout << "\n\n*** End of Program ***\n\n";
}

int display_menu ()

{
	int	selection;

	cout << "\n1. Record a Transaction"
		 << "\n2. Transaction History\n"
		 << "\n0. Exit Program"
		 << "\n\nPlease enter your selection: " ;

	cin >> selection;
	return selection;
}

int transact ()
{
int current_total=1;
int	running_total=1;
int sales;
int refunds;

{
	cout << "\nPlease enter the amount of the transaction\n"
		<< "(payments as positive, refunds as negative): ";
	cin >> current_total;

	while (	current_total ==0)
	{	cout << " Transaction was not recorded.\n";
	
	}
	return current_total;
}}

int transaction_history ()
{
int running_total=1;
int sales;
int refunds=5;
{
	cout << "Transaction History\n"
		 << "-------------------\n";
	return refunds;
}}
Last edited by LuciWiz : 14-Oct-2006 at 18:12. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 14-Oct-2006, 17:49
Sokar Sokar is offline
Member
 
Join Date: May 2005
Posts: 243
Sokar has a spectacular aura aboutSokar has a spectacular aura about

Re: i need urgent help with arrays!!


I am see this,
CPP / C++ / C Code:
while ( menu_choice = display_menu() )
maybe "==" and not"="

What part is not displaying correctly?
  #3  
Old 14-Oct-2006, 17:52
alfie27 alfie27 is offline
New Member
 
Join Date: Oct 2006
Posts: 12
alfie27 is on a distinguished road

Re: i need urgent help with arrays!!


The program runs and compiles with no errors. I don't know how to store a transaction after it has been entered. I think i have to save the value into an array and then have that value flow into the function. I just don't know how to do this?
  #4  
Old 14-Oct-2006, 18:13
Sokar Sokar is offline
Member
 
Join Date: May 2005
Posts: 243
Sokar has a spectacular aura aboutSokar has a spectacular aura about

Re: i need urgent help with arrays!!


Quote:
Originally Posted by alfie27
The program runs and compiles with no errors. I don't know how to store a transaction after it has been entered. I think i have to save the value into an array and then have that value flow into the function. I just don't know how to do this?
Yes two arrays would be good. I would say maybe some thing like this.
CPP / C++ / C Code:
const int ARRAYSIZE = 25;
char clothes[ARRAYSIZE][15];
int transaction [ARRAYSIZE] = {0};
Now just use a variable to use the same index in both arrays. Also do not forget it is up to you to say within the array bounds.
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic vs Static Arrays WaltP Miscellaneous Programming Forum 5 16-Feb-2006 15:54
storing of multidimensional arrays alcoholic C Programming Language 1 06-Jan-2006 07:20
Noob question on c arrays and functions brett C Programming Language 1 20-Apr-2005 03:59
Knight tour (arrays help needed) dilmv C++ Forum 7 18-Oct-2004 14:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:58.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.