Question

OUTPUT MUST MATCH THE IMAGE TO THE TEE. I have the majority of the program written, just having issues with the output. Please make sure to have the right alignment, variable data types and number padding/decimals as shown below!

MUST BE IN C NOT C++/C#! Assume the Item Num is an int that must be padded with zeros (ex: 1234 ---> 00001234)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// This is a sample program as you have said you already have the code for it.

// Utilize this code to format on your side, learn from the code and comments mentioned here.

// Then you can modify your code to get the desired output

#include <stdio.h>
#include<string.h>
#include <stdlib.h>

struct ShoppingList {
    int itemNumber;
    char itemDescription[40];
    double itemPrice;
    int itemCount;
};

int main() {
    struct ShoppingList shoppingList[5];

    //Item Num 1
    shoppingList[0].itemNumber = 345;
    strcpy(shoppingList[0].itemDescription, "Bookshelf");
    shoppingList[0].itemPrice = 78.50;
    shoppingList[0].itemCount = 4;

    //Item num 2
    shoppingList[1].itemNumber = 7474;
    strcpy(shoppingList[1].itemDescription ,"Pen");
    shoppingList[1].itemPrice = 2.99;
    shoppingList[1].itemCount = 100;

    //Item num 3
    shoppingList[2].itemNumber = 987;
    strcpy(shoppingList[2].itemDescription,"Chair");
    shoppingList[2].itemPrice = 129.99;
    shoppingList[2].itemCount = 6;

    //Item num 4
    shoppingList[3].itemNumber = 2342;
    strcpy(shoppingList[3].itemDescription ,"Camera");
    shoppingList[3].itemPrice = 1295.40;
    shoppingList[3].itemCount = 3;

    //Item num 5
    shoppingList[4].itemNumber = 2731;
    strcpy(shoppingList[4].itemDescription, "Table");
    shoppingList[4].itemPrice = 185.40;
    shoppingList[4].itemCount = 2;

    printf("\nItem Num Description Price Count Extended Price\n\n");

    for(int i=0; i<5; i++) {
        int counter = 0;
        char buffer[10];
        snprintf(buffer, 10, "%d", shoppingList[i].itemNumber);
        counter = strlen(buffer);

        // length("Item Number") = 8
        char zeros[7] = "";

        while(counter<6) {
            strcat(zeros,"0");
            counter++;
        }

        // copying the whole item number(with the zeros) into buffer to make it string
        sprintf(buffer, "%s%d", zeros, shoppingList[i].itemNumber);

        // Printing two consecutive strings buffer and description at once
        printf("%8s%14s ", buffer, shoppingList[i].itemDescription);

        // Converting price into string
        sprintf(buffer, "$%.2f", shoppingList[i].itemPrice);

        // Printing string price in a formatted way i.e. with spaces for extra positions
        printf("%10s ", buffer);

        // converting count to string
        sprintf(buffer, "%d", shoppingList[i].itemCount);

        // Printing string count with format to align
        printf("%5s ", buffer);

        // converting extended price to string
        sprintf(buffer, "$%.2f", shoppingList[i].itemPrice*shoppingList[i].itemCount);

        // Printing extended price
        printf("%14s \n", buffer);
    }

    return 0;
}
Add a comment
Know the answer?
Add Answer to:
OUTPUT MUST MATCH THE IMAGE TO THE TEE. I have the majority of the program written,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Goals . Understand how to implement operator overloading in C++ Warning: Programs must compile us...

    c++ format Goals . Understand how to implement operator overloading in C++ Warning: Programs must compile using gt+ on the Computer Science Linux systems. If your code does not compile on CS machines you will get 0 for the assignment. Organize your files into folders by lab assignment. For this assignment, create a folder called Lab9. A. Read Chapter 18 B. Create a new class called RationalNumber to represent fractions. The class should have the following capabilities: 1) It should...

  • Hello, I need help with these two functions blockPrint and wordPrint.The program is written in C....

    Hello, I need help with these two functions blockPrint and wordPrint.The program is written in C. Thank you. ent the prototype for blockPrint. a) Intextfunctions.h, uncon Write the function definition for block Print dentical characters on a separate line. (See example This function should print each group (block) of ident output below) Example: Example: Incoming string: "Tbeehiklssuy Output (to the screen): Incoming string: "Java Programming Output to the screen: ee POOH da al Edit vour main function.include test calls and...

  • I need help building code in python for this: Create a program that: Creates a sales...

    I need help building code in python for this: Create a program that: Creates a sales receipt, displays the receipt entries and totals, and saves the receipt entries to a file Prompt the user to enter the Item Name Item Quantity Item Price Display the item name, the quantity, and item price, and the extended price (Item Quantity multiplied by Item Price) after the entry is made Save the item name, quantity, item price, and extended price to a file...

  • This program will reinforce our knowledge on basic ‘C’ program control, arrays, and editing and compiling...

    This program will reinforce our knowledge on basic ‘C’ program control, arrays, and editing and compiling ‘C’ programs. The objective of this assignment is to create a program that tallies a shopping list of items and displays each selected item, item cost, and total cost of all the selected items plus tax. The program will setup a simple sporting goods store with a few items and prices. The user will submit a shopping list in a textfile and submit it...

  • program must be written in python and have commentary. thank you 3. File Encryption and Decryption...

    program must be written in python and have commentary. thank you 3. File Encryption and Decryption Write a program that uses a dictionary to assign "codes" to each letter of the alphabet. For example: codes-{A':'8','a' :'9', 'B' : e','b' :'#,, etc ) Using this example, the letter A would be assigned the symbol %, the letter a would be assigned the number 9, the letter B would be assigned the symbol e, and so forth. The program should open a...

  • 1. (40 pts) Note: All programs MUST run in Ubuntu. Following the example C program in...

    1. (40 pts) Note: All programs MUST run in Ubuntu. Following the example C program in Folio consisting of three files (a.c, a.h, main.c), write a C program that consists of three files mysquare.h, mysquare.c andmyMain.c. Below is the mysquare.h prototype #include <stdlib.h> #include <stdio.h> void generateNums(int *myarr, int len); void squareNums(int *myarr, int len); void printNums(int *myarr, int len); mysquare.h must contain only the function declarations (prototypes) listed above generateNums function should generate len random integers in the range...

  • This application is for you, the shopper in mind. Putting together an itemized shopping list that...

    This application is for you, the shopper in mind. Putting together an itemized shopping list that contains the items you need, the items you want, and the anticipated cost, this program will generate a total price. This way you can decide if your shopping budget fits the bill. Example list: Price List Binder paper: 2.29 Mop: 7.50 Scouring pads: 5 Your application program will create and write a new list to an output file in which the need and wish...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

  • You will write a C program, q1 sequence.c, that computes the value of the nth term...

    You will write a C program, q1 sequence.c, that computes the value of the nth term in any recursive sequence with the following structure: an = c1 · an−1 + c2 · an−2 a0 > 0 a1 > 0 c1 6= 0 c2 6= 0 Your C program will take 5 integer arguments on the command line: n, a0, a1, c1 and c2. n must be an integer greater than or equal to 0. If more or fewer arguments are...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT