Question

3) Review the problem in Exercise 6.22 on page 271 in the book. (Total Sales) Use a double-subscripted array to solve the fo

hi I need help on this C programming problem and I want exact same out also please use functions to break down main and methods.
thank you

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

If you have any doubts,please give me comment...

#include<stdio.h>

#define MAX_SIZE 5

int main(){

const int max_col=5,max_row=4;

double sales[max_row][max_col];

int i, j;

for(i=0; i<max_row; i++)

for(j=0; j<max_col;j++)

sales[i][j] = 0.0;

int salesperson, product;

double total_sales;

printf("Enter the salesperson, product, and total sales.\n");

printf("Enter -1 for the salesperson to end input.\n");

scanf("%d", &salesperson);

while(salesperson!=-1){

scanf("%d %lf", &product, &total_sales);

sales[salesperson][product] = total_sales;

scanf("%d", &salesperson);

}

double total[max_col];

for(i=0; i<max_col; i++)

total[i] = 0.0;

printf("\nThe total sales for each salesperson are displayed at the end of each row, and the total sales for each product are displayed at the bottom of each column.\n");

printf("\n%-4c", ' ');

for(i=0; i<max_col; i++)

printf("%4d\t",i);

printf("\n");

for(i=0; i<max_row; i++){

printf("%-4d", i);

double tot=0.0;

for(j=0; j<max_col; j++){

printf("%.2lf\t", sales[i][j]);

tot+=sales[i][j];

total[j]+=sales[i][j];

}

printf("%.2f\n", tot);

}

printf("%-4c", ' ');

for(i=0; i<max_col; i++)

printf("%.2lf\t", total[i]);

printf("\n");

return 0;

}

Add a comment
Know the answer?
Add Answer to:
hi I need help on this C programming problem and I want exact same out also...
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
  • ho, then print the message "Next flight leaves in 3 hours." 6.22 Total Sales) Use a...

    ho, then print the message "Next flight leaves in 3 hours." 6.22 Total Sales) Use a two-dimensional array to solve the following problem. A company has four salespeople (I to 4) who sell five diferent products (I to 5). Once a day, each salesperson pases in a slip for each different type of product sold. Each slip contains: a) b) c) The salesperson numbor The product number The total dollar value of that product sold that day Thus, each salesperson...

  • Need help with this programming please this is the instruction my teacher provided Write a C++...

    Need help with this programming please this is the instruction my teacher provided Write a C++ class called "Sales" and a main( ) function that uses the class. Also, write documentation of your project. Below is a specification of the class. . INTRODUCTION A company has four salespeople (1 to 4) who sell five different products ( to 5)1. Once a day each salesperson passes in a slip for each different type of product sold. Each slip contains: The salesperson...

  • Hi i need Help. i use MYSQL command line. THE QUESTION ARE BELOW please check the...

    Hi i need Help. i use MYSQL command line. THE QUESTION ARE BELOW please check the answer before you submit because sometimes query gives error thank you For Full database of SQL you can DOWNLOAD from this link: https://drive.google.com/file/d/1xh1TcBfMtvKoxvJr7Csgnts68fF53Q1t/view?usp=sharing ------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- What are the total sales for each year. Note that you will need to use the YEAR function. Order by year with the newest year first. ------------------------------------------------------- How many employees have no customers? ------------------------------------------------------------------ List the total sales for...

  • I need help with the following and written in c++ thank you!: 1) replace the 2D...

    I need help with the following and written in c++ thank you!: 1) replace the 2D arrays with vectors 2) add a constructor to the Sudoku class that reads the initial configuration from a file 3) adds a function to the Sudoku class that writes the final Sudoku grid to a file or to the standard output device, cout. Sudoku.h #pragma once /* notes sudoku() default constructor precondition : none postcondition: grid is initialized to 0 sudoku(g[][9]) 1-parameter constructor precondition...

  • Assignment3 - Protected View - Saved to this PC ejembi jeremy X File Home Insert DesignLayout Ref...

    please can i get the answer for the 3rd question Assignment3 - Protected View - Saved to this PC ejembi jeremy X File Home Insert DesignLayout References MailingsReview View Help Tell me what you want to do PROTECTED VIEW Be careful-files from the intermet can contain vinuses. Unless you ned to edi, it's safer to stay in Protected View Enable Editing Write a program that will read all this information for last month's sales and summarize the total sales by...

  • HI I was wondering if I can get help with this problem. Cheryl Montoya picked up...

    HI I was wondering if I can get help with this problem. Cheryl Montoya picked up the phone and called her boss, Wes Chan, the vice president of marketing at Piedmont Fasteners Corporation: “Wes, I’m not sure how to go about answering the questions that came up at the meeting with the president yesterday.” "What's the problem?" “The president wanted to know the break-even point for each of the company’s products, but I am having trouble figuring them out.” “I’m...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • this is Matlab. Three images are consecutive and connected. I NEED PROBLEM 2 Chapter 6 Programming in Matlab Week 6 THE ALTERNATING HARMONIC SERIES The alternating harmonic series converges to the na...

    this is Matlab. Three images are consecutive and connected. I NEED PROBLEM 2 Chapter 6 Programming in Matlab Week 6 THE ALTERNATING HARMONIC SERIES The alternating harmonic series converges to the natural log of 2 +--...-In(2) = 0.6931471806 -1--+ Because of this, we can use the alternating harmonic series to approximate the In(2). But how far out do you have to take the series to get a good approximation of the final answer? We can use a while loop to...

  • Please help i need a C++ version of this code and keep getting java versions. Please...

    Please help i need a C++ version of this code and keep getting java versions. Please C++ only Purpose: This lab will give you experience harnessing an existing backtracking algorithm for the eight queens problem, and seeing its results displayed on your console window (that is, the location of standard output). Lab A mostly complete version of the eight queens problem has been provided for you to download. This version has the class Queens nearly completed. You are to provide...

  • Hello guys, i really need your help me solve problem with my assignment excel spreadsheet. how...

    Hello guys, i really need your help me solve problem with my assignment excel spreadsheet. how i put into value in column right (total : subtotal: HST: Amount Due: ) ? how can i solve problem like e.g =B2*B3 or =C4+ E4 or ISNUMBER? I am new to excel spreadsheet, i will learn from you, thank you so much Problem 2: Invoice Figure 3. You may use the Item, Quantity and List_Price data as provided. • Discount Rate, Discount Threshold...

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