This is my first program I've ever written. i got most of it working but the linear seach i put in.. when i try to compile it says the second parameter does not aggree. i try to use a pointer but i must not be using it right..
anyone have a clue?
#include <stdio.h>
#include <string.h>
#define k 3
#define u 3
int lin_search( int target, int array[], int n );
int bal = 0;
int accN = 0;
int intvar = 0;
int index = 0;
struct account
{
int accountNum;
int balance;
};
int main( void )
{
struct account accInfo[4];
int aCount = 0;
int W = 0;
int f = 0;
int e = 0;
struct accInfo (*mypointer)[4];
for(aCount = 0; aCount < 4 ; aCount++ )
{
printf("Enter account number\n" );
scanf("%d", &accInfo[aCount].accountNum );
accInfo[aCount].balance = 0;
}
for (W = 0 ; W < aCount ; W++ )
{
printf("\n\nAccount number %d has a balance of %d,",accInfo[W].accountNum, accInfo[W].balance);
}
for (f = 0; f<4; f++) /*while (1)*/
{
char trans[3];
int amnt = 0;
int b = 0;
printf("\n\nEnter transaction type. \n");
scanf("%s", trans);
printf("\nEnter amount. \n");
scanf("%d",&amnt);
printf("\n\nEnter account number.\n");
scanf("%d", &accN);
index = lin_search( accN, mypointer->balance, 4); /*<------the pointer here*/
if ( index == -1 )
{
printf( "Account number not found\n\n");
}
else
{
b= accN-1;
if ( strcmp(trans,"CR")== 0)
{
accInfo.balance = accInfo.balance +amnt;
}
if ( strcmp(trans,"DB")== 0)
{
accInfo.balance = accInfo.balance - amnt;
}
}
}
for (e = 0; e< aCount; e++)
{
printf("Bank Account %d has a balance of %d\n", accInfo[e].accountNum, accInfo[e].balance);
}
return 0;
}
int lin_search( int target, int array[], int n )
{
int i;
for ( i = 0; i < n; i++)
{
if ( array[ i ] == target )
return i;
}
return -1;
}
anyone have a clue?
#include <stdio.h>
#include <string.h>
#define k 3
#define u 3
int lin_search( int target, int array[], int n );
int bal = 0;
int accN = 0;
int intvar = 0;
int index = 0;
struct account
{
int accountNum;
int balance;
};
int main( void )
{
struct account accInfo[4];
int aCount = 0;
int W = 0;
int f = 0;
int e = 0;
struct accInfo (*mypointer)[4];
for(aCount = 0; aCount < 4 ; aCount++ )
{
printf("Enter account number\n" );
scanf("%d", &accInfo[aCount].accountNum );
accInfo[aCount].balance = 0;
}
for (W = 0 ; W < aCount ; W++ )
{
printf("\n\nAccount number %d has a balance of %d,",accInfo[W].accountNum, accInfo[W].balance);
}
for (f = 0; f<4; f++) /*while (1)*/
{
char trans[3];
int amnt = 0;
int b = 0;
printf("\n\nEnter transaction type. \n");
scanf("%s", trans);
printf("\nEnter amount. \n");
scanf("%d",&amnt);
printf("\n\nEnter account number.\n");
scanf("%d", &accN);
index = lin_search( accN, mypointer->balance, 4); /*<------the pointer here*/
if ( index == -1 )
{
printf( "Account number not found\n\n");
}
else
{
b= accN-1;
if ( strcmp(trans,"CR")== 0)
{
accInfo.balance = accInfo.balance +amnt;
}
if ( strcmp(trans,"DB")== 0)
{
accInfo.balance = accInfo.balance - amnt;
}
}
}
for (e = 0; e< aCount; e++)
{
printf("Bank Account %d has a balance of %d\n", accInfo[e].accountNum, accInfo[e].balance);
}
return 0;
}
int lin_search( int target, int array[], int n )
{
int i;
for ( i = 0; i < n; i++)
{
if ( array[ i ] == target )
return i;
}
return -1;
}