Question

In: Computer Science

Objective: Write this program in the C programming language Loops with input, strings, arrays, and output....

Objective:

Write this program in the C programming language

Loops with input, strings, arrays, and output.

Assignment:

It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory.

You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more than 100 characters per book title title. Use malloc to allocate the strings in the array.

So, it will be a menu:

  1. Enter book information
  2. List all books and prices
  3. List total value of inventory

Solutions

Expert Solution

Please find the code below:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){

   char **books;
   float price[10];

   int count = 0;
   int i;
   books = (char **)malloc(10* sizeof(char*));
   for(i=0;i<10;i++){
       books[i] = (char *)malloc(100* sizeof(char));
   }

   int choice;
   while(1){
       printf("Enter book information\n");
       printf("List all books and prices\n");
       printf("List total value of inventory\n");
       printf("Enter your choice : ");
       scanf("%d",&choice);
       if(choice==1){
           printf("Enter book name : ");
           scanf("%s",books[count]);
           printf("Enter book price : ");
           scanf("%f",&price[count]);
           count++;
       }else if(choice==2){
           printf("%-20s%-20s\n","Book Name","Price");
           int i;
           for(i=0;i<count;i++){
               printf("%-20s%-20.2f\n",books[i],price[i]);
           }
       }else if(choice==3){
           printf("%-20s%-20s\n","S.NO","Book Name");
           int i;
           for(i=0;i<count;i++){
               printf("%-20d%-20.2f\n",i+1,books[i]);
           }
       }
       printf("\n\n");
   }

   return 0;
}

output:


Related Solutions

In C Programming Language Write a program to output to a text log file a new...
In C Programming Language Write a program to output to a text log file a new line starting with day time date followed by the message "SUCCESSFUL". Please screenshot the results.
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
C Programming: Write a program that accepts 2 arguments, an input file and an output file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file. The program is to store in the output file the contents of the input file in reverse. If the input file looks like this: Hello World.\n This is Line 2\n This is the end.\n then the output file should look like this: \n .dne eht si sihT\n 2 eniL si sihT\n .dlroW olleH The main program should look like this: int main(int argc, char...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
Write a program to create a tree randomly. You can use C++ programming language. The input...
Write a program to create a tree randomly. You can use C++ programming language. The input is the number of vertices in the tree, and the output is an adjacent list of the tree. (Managed to complete this assignment with a binary tree. But, was told I needed a general tree instead)
in the c programming language input is given in the form The input will be of...
in the c programming language input is given in the form The input will be of the form [number of terms] [coefficient k] [exponent k] … [coefficient 1] [exponent 1] eg. 5 ─3 7 824 5 ─7 3 1 2 9 0 in this there are 5 terms with -3x^7 being the highest /* Initialize all coefficients and exponents of the polynomial to zero. */ void init_polynom( int coeff[ ], int exp[ ] ) { /* ADD YOUR CODE HERE...
7.3 Loops: Output range with increment of 10 IN CORAL LANGUAGE zyBooks Write a program whose...
7.3 Loops: Output range with increment of 10 IN CORAL LANGUAGE zyBooks Write a program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is -15 30, the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in 20 5, the output is: Second integer...
Programming lang C++ Write a program that reads 10,000 words into an array of strings. The...
Programming lang C++ Write a program that reads 10,000 words into an array of strings. The program will then read a second file that contains an undetermined number of words and search the first array for each word. The program will then report the number of words in the second list that were found on the first list.
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT