Write a program to perform the following: Create an array of 7 double random values (the price of items) between 1.0 and 100.0. Create an array of 7 integer random values(units of items sold) between 0 and 100. Create an array called “total sale” which contains the total sale for each item. Calculate the total sale for this store and display it If the number of items sold is more than 50, print that item#? needs to be reordered.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C Programming 

Write a program to perform the following:

  • Create an array of 7 double random values (the price of items) between 1.0 and 100.0.
  • Create an array of 7 integer random values(units of items sold) between 0 and 100.
  • Create an array called “total sale” which contains the total sale for each item.
  • Calculate the total sale for this store and display it
  • If the number of items sold is more than 50, print that item#? needs to be reordered.

Display Example; -------------------------------------------

item # Price (random) Units Sold (random) Total Sale (price*units sold)
1 25.23 2 50.46
2 3.45 100 345.00
3 40.56 34 1,379.04
: : : :
7 12.35 48 592.80

The total sale of this store is ???.

Item #3 needs to be reordered.

------------------------------------------------------------

1. Must create functions to generate random numbers for each array

2. Must use a function to calculate the sale of each item

3. Do not use Exit statement.

4. Do not use global variables.

5. Single return from a function.

Expert Solution
Step 1

Program code:

#include <stdio.h>
#include <stdlib.h> 
#include <time.h> 
double doublerand(double low, double high ) /* function to generate double type random number */
{
    srand((unsigned int)clock());
     return ( (double)rand() * ( high - low ) ) / (double)RAND_MAX + low;
}
int intrand(int lower, int upper)  /* function to generate integer type random number */

    return (rand() % (upper - lower + 1)) + lower; 
        

double sales(int unit, double price) /* function to compute sales */
{
    return unit*price;
}

int main()
{
    double Price[7];
    int Units[7];
    double totalSales[7], storeSales=0.0;
    int i;
    for(i=0;i<7;i++)
    {
        Price[i]=doublerand(1.0,100.0);  /* function call to generate double type random number */
        Units[i]=intrand(0,100);  /* function call to generate integer type random number */
        totalSales[i]=sales(Units[i],Price[i]); /* function call to calculate total sales */
        storeSales +=totalSales[i]; /* calculate the store sales*/
    }
    printf("Display Example;--------------------------------------\n");
    printf("item#  Price(random) Units Sold(random) Total Sales(Price*Units Sold)\n");
    for(i=0;i<7;i++)
    printf("%-5d%7.2lf%15d%25.2lf\n",i+1,Price[i],Units[i],totalSales[i]); /* display details */
    printf("\nThe total sale of this store is: %.2lf",storeSales);
    for(i=0;i<7;i++)
    {
        if(Units[i]>50) /* check for units solds>50*/
        printf("\nItem #%d needs to be recordered.",i+1);
    }
    printf("\n------------------------------------------------------");
    return 0;
}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education