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
C++ Language Write a program that reads the numbers.txt file and stores it into an array...
C++ Language Write a program that reads the numbers.txt file and stores it into an array of integers. Use the sample functions in the text and in the notes from chapter 8 to sort the array in ascending order (low to high). You can use either method (bubble or selection sort) to accomplish this. Then store the sorted array into an output file sorted Numbers.txt. There are 100 values both positive and negative integers in this file.
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.
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...
Write a C-based language program in visual studio that uses an array of structs that stores...
Write a C-based language program in visual studio that uses an array of structs that stores student information including name, age, GPA as a float, and grade level as a string (e.g., “freshmen,”). Write the same program in the same language without using structs.
c# language Write a program that takes in a number from the user. Then it prints...
c# language Write a program that takes in a number from the user. Then it prints a statement telling the user if the number is even or odd. If the number is odd, it counts down from the number to 0 and prints the countdown on the screen, each number on a new line. If the number is even, it counts down from the number to 0, only even numbers. For example, if the user enters 5, the output will...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT