473,480 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to right justify a column

Hello group,

I am feeling pretty good about this program. I am just learning and
am trying to get the basics down. I would like to ask if someone
could tell me how to right justify the BALANCE column in my program's
output.

===============
Here is my code:
===============

#include <stdio.h>

int main (void)
{
int i;
int accountNumber[10];
char lastName[10][30];
float accountBalance[10];

printf("Enter account number, last name, and balance.\n");
printf("Enter -999 to end input.\n");
for (i = 0; i < 10; i++)
{

printf("? ");
scanf ("%i", &accountNumber[i]);

if (accountNumber[i] == -999)
{
printf("\n");

break;
}

scanf("%s", lastName[i]);
scanf("%f", &accountBalance[i]);

} /* End for loop */

printf("%-15s%-15s%-15s\n","ACCOUNT","LAST NAME","BALANCE");

for(i = 0; (i < 10) && (accountNumber[i] != -999); i++)
{

printf("%-15d%-15s%-15.2f", accountNumber[i],
lastName[i], accountBalance[i]);

printf("\n");
}

printf("\n\n");

return 0;

} /* End main */
Nov 13 '05 #1
2 18703
jw****@berkeley.edu wrote:
Hello group,

I am feeling pretty good about this program. I am just learning and
am trying to get the basics down. I would like to ask if someone
could tell me how to right justify the BALANCE column in my program's
output.

===============
Here is my code:
===============

#include <stdio.h>

int main (void)
{
int i;
int accountNumber[10];
char lastName[10][30];
float accountBalance[10];

printf("Enter account number, last name, and balance.\n");
printf("Enter -999 to end input.\n");
for (i = 0; i < 10; i++)
{

printf("? ");
scanf ("%i", &accountNumber[i]);

if (accountNumber[i] == -999)
{
printf("\n");

break;
}

scanf("%s", lastName[i]);
scanf("%f", &accountBalance[i]);

} /* End for loop */

printf("%-15s%-15s%-15s\n","ACCOUNT","LAST NAME","BALANCE"); Use: printf("%-15s%-15s%15s\n","ACCOUNT","LAST NAME","BALANCE");
for(i = 0; (i < 10) && (accountNumber[i] != -999); i++)
{

printf("%-15d%-15s%-15.2f", accountNumber[i],
lastName[i], accountBalance[i]); Use: printf("%-15d%-15s%15.2f", accountNumber[i],
lastName[i], accountBalance[i]);
printf("\n");
}

printf("\n\n");

return 0;

} /* End main */

Using the - modifier in the format left justifies the result within
the field. Removing it causes right justification.

Rgds,
Shanmu.

Nov 13 '05 #2
Shanmu,

Wow do I feel silly. I kept looking around the Internet for how to do
it. No wonder I couldn't find it considering it happens by default.
Oh well, thanks for helping me out. :o)
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
9420
by: Leonard | last post by:
How do I right justify input data in a textbox? I have some textboxes that are used to input numbers, and I would like to right justify them.
0
1380
by: David Holmes | last post by:
Hi Acc 97 is it possible to right justify numbers in a list box Thanks in advance Dave Holmes
1
18306
by: Kevin R | last post by:
Hi All, I am using for(i = . . . . .) sw.WriteLine(string.Format("{0} {1}", num1, num2)); and I am getting 12 123
2
2114
by: Tina | last post by:
Is there any way to get the text property to right justify in controls like Hyperlink buttons and labels? Thanks, T
2
1633
by: John Wilson | last post by:
Here's a dumb question from a learner: In a datagrid in a web page, how do I right justify a column of figures? I bet its easy once you know. John Wilson
9
20062
by: JG | last post by:
I'm new obviously to html and I'm looking for a way put an image on the right side of the page opposite text on the left. How does one do this? I've heard of text wrapping of an image but not sure...
5
2693
by: tshad | last post by:
I have a datagrid that I cannot get to right justify a money amount (which is just a label). No matter what I do - it still right justifies it. <asp:TemplateColumn Visible="true"...
2
4602
by: eighthman11 | last post by:
Hello everyone, I'm using Access 2000 and SQL 8.0 This maybe easy but I can't figure it out. I have a linked access table to a SQL server table. I use this table on a Grid on an Access form. ...
1
2849
by: samueltilden | last post by:
I have Infragistics 2007, Volume 3: I have a UltraStatusBar with two UltraStatusPanels: 1. Left Panel and 2. Right Panel I want the Right Panel to appear on the right and to have its text...
0
7043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6737
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.