Question

In: Computer Science

In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of computers sold...

In a C language program CODE BLOCKS !!!!!!!!

Program that stores the number of computers sold by three vendors in four different zones. Is required:
 Request the sale amount of each seller by zone, the values must be entered through the keyboard and validate that it does not accept negative numbers.
 Menu that requests the operation to be carried out. In case of entering an invalid data, send an error message and request the operation again.
 Option to perform another calculation

Note: The code must perform the calculations going through the array, operations assigning the values directly to the array elements are not accepted.

Solutions

Expert Solution

Code in C

#include <stdio.h> 
#include <stdlib.h>
void print_menu(){
        printf("Enter 1 to get total sales for each vendor.\n");
        printf("Enter 2 to get total sales for each zones.\n");
        printf("Enter 3 to get total sales across all vendors and zones.\n");
        printf("Enter 0 to exit program.\n");
}
int main(){
        //2 vendors and 4 zones
        const int num_vendors=3, num_zones=4;
        int arr[num_vendors][num_zones];
        
        //get sale amount
        for(int i=0;i<num_vendors;i++){
                for(int j=0;j<num_zones;j++){
                        int x;
                        printf("Enter sale amount for vendor %d in zone %d: ", i+1, j+1);
                        scanf("%d", &x);
                        while(x<0){
                                printf("Sales amount cannot be negative!\nEnter sale amount: ");
                                scanf("%d", &x);
                        }
                        arr[i][j]=x;
                }
        }
        int op;
        do{
                print_menu();
                scanf("%d", &op);
                while(op<0||op>3){
                        printf("Invalid option\nPlease input a valid option: ");
                        scanf("%d", &op);
                }
                switch(op){
                        case 1: {
                                for(int i=0;i<num_vendors;i++){
                                        int total=0;
                                        for(int j=0;j<num_zones;j++){
                                                total+=arr[i][j];
                                        }
                                        printf("Total sales for vendor %d = %d\n", i+1, total);
                                }
                                break;
                        }
                        case 2: {
                                for(int i=0;i<num_zones;i++){
                                        int total=0;
                                        for(int j=0;j<num_vendors;j++){
                                                total+=arr[j][i];
                                        }
                                        printf("Total sales for zone %d = %d\n", i+1, total);
                                }
                                break;
                        }
                        case 3: {
                                int total=0;
                                for(int i=0;i<num_vendors;i++){
                                        for(int j=0;j<num_zones;j++){
                                                total+=arr[i][j];
                                        }
                                }
                                printf("Total sales = %d\n", total);
                                break;
                        }
                }
        }while(op!=0);
}

Sample Console Input/Output

Enter sale amount for vendor 1 in zone 1: -2
Sales amount cannot be negative!
Enter sale amount: 1
Enter sale amount for vendor 1 in zone 2: 2
Enter sale amount for vendor 1 in zone 3: 
3
Enter sale amount for vendor 1 in zone 4: 4
Enter sale amount for vendor 2 in zone 1: 5
Enter sale amount for vendor 2 in zone 2: 3
Enter sale amount for vendor 2 in zone 3: 2
Enter sale amount for vendor 2 in zone 4: 4
Enter sale amount for vendor 3 in zone 1: 2
Enter sale amount for vendor 3 in zone 2: 3
Enter sale amount for vendor 3 in zone 3: 4
Enter sale amount for vendor 3 in zone 4: 1
Enter 1 to get total sales for each vendor.
Enter 2 to get total sales for each zones.
Enter 3 to get total sales across all vendors and zones.
Enter 0 to exit program.
1
Total sales for vendor 1 = 10
Total sales for vendor 2 = 14
Total sales for vendor 3 = 10
Enter 1 to get total sales for each vendor.
Enter 2 to get total sales for each zones.
Enter 3 to get total sales across all vendors and zones.
Enter 0 to exit program.
2
Total sales for zone 1 = 8
Total sales for zone 2 = 8
Total sales for zone 3 = 9
Total sales for zone 4 = 9
Enter 1 to get total sales for each vendor.
Enter 2 to get total sales for each zones.
Enter 3 to get total sales across all vendors and zones.
Enter 0 to exit program.
3
Total sales = 34
Enter 1 to get total sales for each vendor.
Enter 2 to get total sales for each zones.
Enter 3 to get total sales across all vendors and zones.
Enter 0 to exit program.
0

Let me know in comments if you have any doubts. Do leave a thumbs up if this was helpful.


Related Solutions

In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of votes obtained...
In a C language program CODE BLOCKS !!!!!!!! Program that stores the number of votes obtained by 3 amounts in five different zones. Is required: + Request the total of votes by zone of each candidate, the values must be entered on the keyboard and validate that it does not accept negative numbers + Menu that requests the operation to be performed, in case of entering an invalid data send an error message and request the operation again + Option...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes...
Programming language: C++   suggested software: Code::Blocks Develop an algorithm and write a C++ program that computes the final score of a baseball game. Use a loop to read the number of runs scored by both teams during each of nine innings. Display the final score afterward. Submit your design, code, and execution result via file, if possible
Two computer stores recorded the number of computers sold in a week along with the sizes...
Two computer stores recorded the number of computers sold in a week along with the sizes of their hard drives. At a = .05, test the claim that the distribution of hard drives and the store where the computers were bought are not related. store one sold 13 20gb, 11 40gb, 11 80gb, 8 160gb. store two sold 104 20gb, 33 40gb, 15 80 gb, 10 160gb Hypothesis with claim Draw Curve Critical Value Test Value Decision Summary
Two computer stores recorded the number of computers sold in a week along with the sizes...
Two computer stores recorded the number of computers sold in a week along with the sizes of their hard drives. At a = .05, test the claim that the distribution of hard drives and the store where the computers were bought are not related. store one sold 13 20gb, 11 40gb, 11 80gb, 8 160gb. store two sold 104 20gb, 33 40gb, 15 80 gb, 10 160gb Hypothesis with claim Draw Curve Critical Value Test Value Decision Summary
Please code in C language. Server program: The server program provides a search to check for...
Please code in C language. Server program: The server program provides a search to check for a specific value in an integer array. The client writes a struct containing 3 elements: an integer value to search for, the size of an integer array which is 10 or less, and an integer array to the server through a FIFO. The server reads the struct from the FIFO and checks the array for the search value. If the search value appears in...
Code in C-language programming description about convert binary number to decimal number.
Code in C-language programming description about convert binary number to decimal number.
C LANGUAGE ONLY Write a C program to count the total number of duplicate elements in...
C LANGUAGE ONLY Write a C program to count the total number of duplicate elements in an array. Enter the number of elements to be stored in the array: 3 Input 3 elements in the arrangement: element [0]: 5 element [1]: 1 element [2]: 1 Expected output: The total number of duplicate elements found in the array is: 1
Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
Write a C program (using Code::blocks) that outputs a formatted header line and creates 10 children...
Write a C program (using Code::blocks) that outputs a formatted header line and creates 10 children processes each of which displays a line of the output as shown below. Notice the values of Child no and x, they have to be the same as shown here while the processes PIDs values are based on the what your system assigns to these processes. Child    PID        PPID      X 0           13654    13653    5 1           13655    13653    10 2           13656    13653    15 3           13657   ...
c++ is the language Code an O(nlog(n)) algorithm to count the number of inversions DO NOT...
c++ is the language Code an O(nlog(n)) algorithm to count the number of inversions DO NOT ADD OR EDIT FUNCTIONS USE THESE ONLY DO NOT EDIT THE TEST FILE EITHER countInv.cpp #include <vector> #include <algorithm> using namespace std; int mergeInv(vector<int>& nums, vector<int>& left, vector<int>& right) { // You will need this helper function that calculates the inversion while merging // Your code here } int countInv(vector<int>&nums) { // Your code here } countInv_test.cpp #include <iostream> #include <vector> using namespace std;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT