alingment :


DOTS REPRESENT SPACES
DESIRED OUTPUT
Item................................................Price

Burger..............................................100
pizza.............................................. ..50
patty................................................ 25
coke.............................................. ..10

OUTPUT BY PROG.

Item                                                   Price

Burger                                                     100
pizza                                                     50
patty                                                    25
coca-cola                                                   10

DISPLAY CODE

for(k=0; k<no; k++)
 {
 cout<<endl;
  for(m=0; arr[k][m]!='\0'; m++)
  {
  cout<<arr[k][m];
  }
  cout<<"                               "<<price[k];
 }

Interger array input without asking for number of terms

/* Name- inp_arr
   parameters- none
   output - none ()*/

#include<iostream.h>
#include<conio.h>
 void inp_array ()
 {
 int a[100],i;
 cout<<"Enter the integer array and press 0011 after the last therm"<<endl;
 for(i=0;a[i]!=0011;i++)
  {
  cin>>a[i];
j++;
  }



  return;
 }

j which is the counter for the number for terms assumes -36 values no matter what the input.

Also is it possible to output a array ??

In DISPLAY CODE why do you insist on doing things the hard way (character by character)?

for(k=0; k<no; k++)
{
    cout << arr[k] << setw(20) <<  "<< price[k] << "\n";
}

In the second program where is variable j declared?
The loop on line 11 won't work because the value of i is incremented before he test is made. So if you enter "0011" on the first iteration the value of i will be incremented and then tested for 0011. You have to make the test immediately after the integer is entered.

int j = 0;
for(int i = 0; ; i++)
{
    cin>>a[i];
   if( a[i] == 11)
       break;
}

trying ....btw can yuo explain setw fuction ?? also break;
is a gud idea indeed dunno y it didn't cum to my mind.

Itz still not working, if in a item letters are less..... the price comes closer to it.

burger...............................................................20
bun................................................................05

you might have to calculate the value you put in the setw function on each line. For example if you want 20 spaces after the menu item on the first line ( "burger" ) then you will want to put 23 spaces on the next line so that the prices lign up right (assuming you are using a fixed-width font for display. If you are using a variable-width font then there isn't much you can do about the alignment with plain c++ code).

I think the input programwould be cleaner as:

/* Name- inp_arr
   parameters- none
   output - none ()*/

#include<iostream.h>
#include<conio.h>
 int main ()       //note this must by "main" to be a valid program
 {
      int a[100]= { 0 } ,  i = 0;
      int input;
      cout<<"Enter the integer array and press 11 after the last therm"<<endl;
      cin >> input;
      while ( i < 100 && input != 11 )
     {
         a[i++] = input;
        cin >>input;
     }
  }

Asking the user to enter "0011" may be dangerous - the input operation might interpret that as an octal value (which equates to 9 in base 10).

Once you entered data into the array, display it like:

ink j;
for( j = 0; j < i; j++ )
     cout << a[j] << "  ";

For the price display, you must also setw( ) for the item names, like:

for(k=0; k<no; k++)
{
    cout << setw( 10) << arr[k] << setw(15) <<  "<< price[k] << "\n";
}

>>For the price display, you must also setw( ) for the item names, like:
Actually, my preference would be to use printf() instead of cout because its a lot simplier to align the text without resorting to calculating the width. But this is c++ and c++ is sometimes clumsy IMO.

how do we use printf ?? isn't print used in Qbasic ?? also Is it possble for mee to change color ?? other guyz of my school have beautiful colored screen while mine is a plane back& white.....plz suggest me something special to get those extra grades.

Don't use printf() -- see vmanes suggestion and you won't have to calculate the spaces as I said before.

As for color -- depends on the compiler you are using. Ancient TurboC is somewhat easy to do. For modern compilers you have to use win32 api console functions.

Here's a page about printf() But you shouldn't use it with C++.

Changing the text color can be done with:
SetConsoleTextAttribute()

This example:

SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),1);
   cout<< "iets";

will make your text blue. Changing the '1' to other values will result in other colors.
Don't forget to #include <windows.h> [edit] Too slow again.. AD is on the roll[/edit]

vmanes codes work like a charm. btw watz teh fuction to change BK color and is it possible to cout with frame rate of 24 frames per sec so that its like moving on the screen.

btw my c++ project is almost done just calculating the bill. And finding how to encrypt pass. I will post it here coz guyz have helped me a lot with it.

To make the background of text blue: SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_BLUE); It was in the link from my previous post

Setconsoletextatt- header file req.
getstdhandle- header file req.
undefined symbols

STD_OUTPUT_HANDLE
BACKGROUND_BLUE

Did you #include <windows.h> as I mentioned?

unable to include windows.h

What operating system are you using? (please don't tell me DOS with Turbo C..)

vista though I start c++ with dos..... linux interface is very tough.

What compiler? VS has the platform SDK standard, but other compilers may require the SDK to be installed

dunno bout all that compiler stuff. leave it.

I have tcc v3.0.

I would strongly recommend that you upgrade to visual studio. It's free and you'll be up to date!
(other free programs are: Ming, bloodshed DevC++)

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.