I'm having trouble writing this program:
5. Write a program that formats product information entered by the user. A session with the program should look like this:
Enter item number: 583
Enter unit price: 13.5
Enter purchase date (mm/dd/yy): 10/24/95
Item Unit Purchase
Price Date
583 $13.50 10/24/95
The item number and date should be left justified; the unit price should be right justified. Allow dollar amounts up to $9999.99. HINT: Use tabs to line up columns.
This is what I've written:
#include <stdio.h>
int main()
{
int item, mm, dd, yy;
float unit;
printf("Enter an item number: ");
scanf("%d", &item);
printf("Enter a purchase date (mm/dd/yy): ");
scanf("%d/%d/%d", &mm, &dd, &yy);
printf("Enter a unit price: ");
scanf("%.2f", &unit);
printf("Item Unit Purchase\n");
printf(" Price Date\n");
printf("%-d $%.2f %-17d/%17d/%17d\n", item, unit, mm/dd/yy);
return 0;
}
(i'm also having trouble when i write out 'Enter purchase date: ' last... so that's why it's in the middle)