By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,483 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

need immediate help with struct !

P: 3
Hi,
I am getting 2 errors when i try to run my program. This is my first time using the struct feature so i'm not sure how to correct my errors. Any help will be greatly appreciated.
Here are the errors i am getting :
error C2440: 'initializing' : cannot convert from 'Transaction_structure [25][25]' to 'Transaction_structure *'
error C2664: 'transact' : cannot convert parameter 1 from 'Transaction_structure [25]' to 'Transaction_structure &'
A reference that is not to 'const' cannot be bound to a non-lvalue
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <cstring>

struct Transaction_structure {
int amt;
char trans_desc[25];
};

const int ARRAYSIZE = 25 ;

int display_menu ();
double transact ( Transaction_structure & , char [] );
void transaction_history ( const double [],
const char [][ ARRAYSIZE ],
const double,
const int,
const Transaction_structure *
);

void main()
{

double trnx_amt [ ARRAYSIZE ] = { 0.0 }, // stores the amount of the transaction
cur_bal = 0.0;

int cur_trnx = 0, // use as index into arrays; skipping index 0)
menu_choice = 0;

char desc [ ARRAYSIZE ] [ ARRAYSIZE ] = { 0 } ; // 2-d array for transaction descriptions
Transaction_structure transaction [ARRAYSIZE][ARRAYSIZE] = {0},
*show = transaction;
for ( int i = 0; i < ARRAYSIZE; i++ )


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

while ( cur_trnx < ARRAYSIZE && ( menu_choice = display_menu () ) )
{
switch ( menu_choice )
{
case 1:
for ( int i = 0; i < ARRAYSIZE; i++ )
if ( trnx_amt [ cur_trnx ] = transact (transaction[i], transaction [ cur_trnx ] ) )
{
cur_bal += trnx_amt [ cur_trnx ] ;
cur_trnx++ ;
}
break ;
case 2:
transaction_history ( trnx_amt, desc, cur_bal, cur_trnx, show );
break ;

default:
cout << "\nInvalid selection, please choose again.\n" ;
}

}

cout << "Closing Account...\n\n";

cout << "\n*** End of Program ***\n" << endl ;

}

int display_menu ()
{
int choice;

cout << "1. Enter a Transaction\n"
<< "2. Transaction History\n\n"
<< "0. Exit Program\n\n"
<< "Please enter your selection: ";
cin >> choice ;
return choice;
}

double transact ( Transaction_structure &tran, char trans_desc [] )
{
double amt;

cout << "\nPlease enter the amount of the transaction. Enter a positive number for\n"
<< "a sale and a negative number if a refund: " ;
cin >> tran.amt;

if ( amt )
{
cout << "\nPlease enter a one-word description of the item sold/returned: " ;
cin >> tran.trans_desc ;
cout << "Transaction recorded.\n\n";
}
else
cout << "*** Zero entered. No transaction will be recorded.\n\n";

return amt;
}

void transaction_history ( const double trnx_amt[],
const char trans_desc [] [ ARRAYSIZE ],
const double cur_bal,
const int cur_trnx,
const Transaction_structure *tran
)
{
double payments = 0.0,
refunds = 0.0;

cout << "Transaction History\n"
<< "-------------------\n\n" ;

for ( int i = 0; i < cur_trnx; i++ )
{
cout << i + 1 << ". " ;
if ( trnx_amt [ i ] > 0 )

{
cout << "Sale of " << trans_desc [i] << ": $" << trnx_amt [ i ] << "\n";
payments += trnx_amt [ i ];
}
else
{
cout << "Refund for " << trans_desc [i] << ": $" << -trnx_amt [ i ] << "\n";
refunds += -trnx_amt [ i ];
}


}
cout << "\n--------------------------------" ;
cout << "\nTotal sales : $" << payments ;
cout << "\nTotal refunds: ($" << refunds << ")" ;
cout << "\nNet : $" << cur_bal
<< "\n--------------------------------\n\n" ;
}
Nov 16 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.