Thread: logic error I think

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    logic error I think

    I believe That there is an error in this function. The program is to act as a upc scanner, it has 2 hard coded arrays 1 for upc codes and 1 for prices. it also has 2 more nonhardcoded arrays, when you enter the upc codes this function is supposed to take in the upc codes check them and put the corrrect vales in the upchold and pricehold arrays , but it isn't. any help would be appreciated.

    Thanks
    Steve
    <code>
    ----------------------------------------------------------------------------------- int newsale ( int UPC [], float PriceHold [], float Price [], int UPCHold [])
    {


    int s, foundSw, count=0, UPCnum, ItemNum=0, x=0;

    cout<<"Please enter your UPC Codes"<<endl;


    while ( 1 )
    {



    cin >> UPCnum;
    if ( UPCnum == 999 )
    break;


    foundSw=0;
    for ( s=0; s<25; s++ )
    {



    if ( UPCnum == UPC[s] )

    {
    foundSw=1;
    break;
    }
    }


    if (foundSw ==1)
    {

    UPCHold [x] = UPC[s];
    PriceHold [x] = Price[s];
    x++;
    }
    else

    cout << "INVALID UPC CODE"<<endl;


    }

    return x;



    }


    ----------------------------------------------------------------------------------
    \code

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Maybe I'm missing something, but your function looks good to me. Are you saying you tried to print the hold arrays after calling this function, and they were blank?
    Code:
    num_of_codes = newsale ( UPC, PriceHold, Price, UPCHold);
    
    cout << "num_of_codes:" << num_of_codes << endl;
    for (i=0; i<num_of_codes; i++)
    {
       cout << "Price:" << PriceHold[i] << endl;
       cout << "UPC:" << UPCHold[i] << endl;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Digital Logic
    By strokebow in forum Tech Board
    Replies: 3
    Last Post: 12-09-2006, 01:05 PM
  2. Logic
    By LordBronz in forum C++ Programming
    Replies: 6
    Last Post: 05-23-2006, 05:41 PM
  3. Actors, cues, event based logic.
    By Shamino in forum Game Programming
    Replies: 2
    Last Post: 04-27-2006, 10:58 PM
  4. Circular Logic
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-15-2001, 08:10 PM