hi. can someone help me with this .
req:
if item code is A description is CHAIR witha a prize of 200 else if itemcode is B description is TABLE with a prize of 500 else item code is C description is PC with a prize of 4000.

output display should be like this.
a.

Itemcode:_______
description :________
prize:_________

output B.

Itemcode:_______
description :________
prize:_________
quantity:______
total amount:__________

totalamount=quantity x prize

thanks for the reply :) godbless

In C, an if/else statement looks like this:

if (condition 1) {
   /* Do condition 1 stuff */
} else if (condition 2) {
   /* Do condition 2 stuff */
} else {
   /* do default stuff */
}

All you need to do is place your logic into that structure and fill in the bodies appropriately.

Try that out and let us know where you get stuck.

A nice (general) way to handle questions like this might be to use a (data) struct (record) ...

/* def'n of struct ... */
typedef struct
{
   char code; /* 'A', 'B' or 'C' */
   char* info; /* a dynamic C string to hold text */
   int dollars;
} Item ;

This keeps all you data together, and you could then use an array of type Item to hold as many Item objects as you have memory available ...

as opposed to using ...

parallel arrays or multi-dimension arrays.

But... if your particular problem is limited to just 3 objects, you might like to use parallel arrays ... and a table look up method, something like this:

const char code[] = { 'A', 'B', 'C' );
const int size = sizeof code / sizeof code[0];

const char* info[] = { "apple_pie", "buns_48", "cherry_crate" );
const int dollars[] = { 10, 20, 30 };


int findIndex( const char code[], int size, char x )
{
   int i;
   for( i = 0; i < size; ++i )
      if( x == code[i] ) return i;
   /* else if reach here ...  */
   return -1; /* the value to indicate NOT found */
}

Then ...

// in main

// perhaps inside a big do loop ... while more?

int index;

// prompt for x, input of a code in range 'A'..'C'

// get index of that code ..

index = findIndex( code, SIZE, x );

// print out info and dollars for that index ..

if( index != -1 )
printf( "You choose %c, %s, costing %d dollars\n",
         x, info[index], dollars[index] );
else
// print out message you need to enter only 'A'..'C'

BUT ... since you just wish to total these 3 items, no need to use a find function ...

// can loop ...

int sumDollars = 0;
int j;
for( j = 0; i < 3; ++ j )
{
   // print out each
   sumDollars += dollars[j];
}
// now can use sumDollars ///
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.