Question

In: Computer Science

Hey guys, So it seems like I made a slight error in my program. So one...

Hey guys,

So it seems like I made a slight error in my program. So one of the requirement for this program is not to show any negatives shown as a output, however my program showed some negative numbers. I was wondering if someone could look over my program and find the error and maybe give it a tweak. I don't want to change my program because I worked so hard for it. Anyway here the assignment at the bottom is my code. Thanks in advance:

In this program, you are to store information about sales people and their individual sales from a company. You are to store the first name and quantity sold for each transaction.

You are to allow records to be stored for sales transactions. In fact, you need to ask the user for the total possible number of sales.

You are to allow data entry of 0 to maximum number of transaction. You are to store in the computer the income for each person for each transaction. No negative sales permitted. Here are the rules for calculating income:

  • The person makes 5 dollars for each item for the first five items sold.
  • The person makes 10 dollars for each item for the next 5 items sold.
  • The person makes 25 dollars for each item for the next 500 items sold.
  • The person makes 35 dollars for each item sold after the 510th item sold.

The income for a person is progressive. He or she makes money for the first 5 items sold + money from the next 5 items sold + money for the next 500 items sold + the money for any other sale.

The program will have three options: * Record a new sale, * Show income from each existing sales transaction, * Quit

Example output

Name          Total Items Sold              Total Income

Tom            1                                  $5.00

Mary            5                                  $25.00

Willie           7                                  $35.00

Jack            511                               $12,610

My code:

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

float incomePower(int itemSold){

  

float incomes;

  

int numbers = 4;

  

int breakpoints[] = {0, 5, 5+5, 5+5+500};

  

float rates[] = {5.0, 10.0, 25.0, 35.0};

  

for (int roc = 0; roc < numbers; roc++) {

if (itemSold <= breakpoints[roc]) {

break;

}

  

if ( roc < numbers - 1 && itemSold >= breakpoints[roc + 1]) {

  

incomes += rates[roc] * (breakpoints[roc + 1] - breakpoints[roc]);

  

} else {

incomes += rates[roc] *(itemSold - breakpoints[roc]);

}

}

  

return incomes;

}

int main(){

  

int megaSale = 0, roc = 0, arrayPointer = 0;

  

printf("\nThe total income of sales of each Person\n");

  

printf("\nEnter the maximum number of sales: \n");

scanf("%d", &megaSale);

  

char names[megaSale][100];

  

int itemsold[megaSale];

  

float totalincome[megaSale];

  

while (1) {

  

int choice;

  

printf("Choose:");

scanf("%d", &choice);

  

switch (choice) {

case 1:

printf("Enter the name of sales person");

scanf("%s", names[arrayPointer]);

  

printf("Enter the number of sale of %s: ", names[arrayPointer]);

scanf("%d", &itemsold[arrayPointer]);

totalincome[arrayPointer] = incomePower(itemsold[arrayPointer]);

  

arrayPointer += 1;

break;

  

case 2:

printf("\nName\t\tTotal Items Sold\t\tTotal Income");

  

for (roc = 0; roc <arrayPointer; roc++) {

  

printf("\n%s\t\t\t%d\t\t\t%.2f\n", names[roc], itemsold[roc], totalincome[roc]);

  

}

break;

  

case 3:

exit(0);

break;

  

default:

printf("Invalid entry");

}

}

  

  

return 0;

}

Solutions

Expert Solution

Hi,

Please find the answer below:

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

Fixes:

This is to increase the readability of the program:
Added the option menu with options 1,2 and 3 below the choose statement.

Fix:

do{
    printf("Enter the number of sale of %s: ", names[arrayPointer]);
    scanf("%d", &itemsold[arrayPointer]);
} while (itemsold[arrayPointer] < 0)


After fix the system will prompt again


The total income of sales of each Person

Enter the maximum number of sales:
4
Choose:
1. Record a new sale:
2. Show income from each existing sales transaction:
3. Quit.
1
Enter the name of sales person:Tom
Enter the number of sale of Tom( No negative sales permitted.):-5
Enter the number of sale of Tom( No negative sales permitted.):5
Choose:
1. Record a new sale:
2. Show income from each existing sales transaction:
3. Quit.

Complete Code:

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

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

float incomePower(int itemSold)
{

    float incomes;

    int numbers = 4;

    int breakpoints[] = {0, 5, 5+5, 5+5+500};

    float rates[] = {5.0, 10.0, 25.0, 35.0};
    int roc;
    for (roc = 0; roc < numbers; roc++)
    {

        if (itemSold <= breakpoints[roc])
        {

            break;

        }


        if ( roc < numbers - 1 && itemSold >= breakpoints[roc + 1])
        {

            incomes += rates[roc] * (breakpoints[roc + 1] - breakpoints[roc]);

        }
        else
        {

            incomes += rates[roc] *(itemSold - breakpoints[roc]);

        }

    }
    return incomes;

}

int main()
{

    int megaSale = 0, roc = 0, arrayPointer = 0;

    printf("\nThe total income of sales of each Person\n");
    printf("\nEnter the maximum number of sales: \n");
    scanf("%d", &megaSale);

    char names[megaSale][100];

    int itemsold[megaSale];
    float totalincome[megaSale];

    while (1)
    {

        int choice;

        printf("Choose:\n");
        printf("1.:Record a new sale\n");
        printf("2.:Show income from each existing sales transaction\n");
        printf("3.:Quit\n");
        scanf("%d", &choice);

        switch (choice)
        {

        case 1:

            printf("Enter the name of sales person:");

            scanf("%s", names[arrayPointer]);

            do
            {
                printf("Enter the number of sale of %s(No negative sales permitted.): ", names[arrayPointer]);
                scanf("%d", &itemsold[arrayPointer]);
            }
            while (itemsold[arrayPointer] < 0);

            totalincome[arrayPointer] = incomePower(itemsold[arrayPointer]);

            arrayPointer += 1;

            break;

        case 2:

            printf("\nName\t\tTotal Items Sold\t\tTotal Income");

            for (roc = 0; roc <arrayPointer; roc++)
            {

                printf("\n%s\t\t\t%d\t\t\t $ %.2f\n", names[roc], itemsold[roc], totalincome[roc]);

            }

            break;

        case 3:

            exit(0);

            break;

        default:

            printf("Invalid entry");

        }

    }


    return 0;

}

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

Run Output:

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


The total income of sales of each Person

Enter the maximum number of sales:
4
Choose:
1.:Record a new sale
2.:Show income from each existing sales transaction
3.:Quit
1
Enter the name of sales person:Tom
Enter the number of sale of Tom(No negative sales permitted.): -1
Enter the number of sale of Tom(No negative sales permitted.): 1
Choose:
1.:Record a new sale
2.:Show income from each existing sales transaction
3.:Quit
1
Enter the name of sales person:Mary
Enter the number of sale of Mary(No negative sales permitted.): 5
Choose:
1.:Record a new sale
2.:Show income from each existing sales transaction
3.:Quit
1
Enter the name of sales person:Willie
Enter the number of sale of Willie(No negative sales permitted.): 7
Choose:
1.:Record a new sale
2.:Show income from each existing sales transaction
3.:Quit
1
Enter the name of sales person:Jack
Enter the number of sale of Jack(No negative sales permitted.): 511
Choose:
1.:Record a new sale
2.:Show income from each existing sales transaction
3.:Quit
2

Name            Total Items Sold                Total Income
Tom                     1                        $ 5.00

Mary                    5                        $ 25.00

Willie                  7                        $ 45.00

Jack                    511                      $ 12610.00
Choose:
1.:Record a new sale
2.:Show income from each existing sales transaction
3.:Quit

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

Screenshot:


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

Hope this helps.


Related Solutions

Hey guys, So I am doing a presentation on the element Gold, Au. Now I could...
Hey guys, So I am doing a presentation on the element Gold, Au. Now I could go look up the information online but I am really running out of time here, could someone provide me with as much information as you can on the elemnt gold(NOTE NOT PLAGIARIZED). Please cite everything and just hook me up with as many paragraphs and information on gold as you can. I will downrate you if you just do a lazy copy paste from...
Hey guys so ive been working on these Radix for quite sometime but I keep hitting...
Hey guys so ive been working on these Radix for quite sometime but I keep hitting roadblocks on my todos. Ive implement the first TODO but I cant get the stringRadixSort to work properly as well nor the ChainOfNodes mergeTwoChainsIntoThird() function. Please feel free to rewrite anything you see wrong with it. Ive also provided the Lab Description down below as well for what the output should be and what to do. Thanks again for your guys help! 1) Implement...
YOU GUYS PROVIDE ME THE WRONG ANSWER SO I NEED THE CORRECT ANS Check my work...
YOU GUYS PROVIDE ME THE WRONG ANSWER SO I NEED THE CORRECT ANS Check my work Check My Work button is now enabledItem 4 Item 4 30 points A private not-for-profit entity is working to create a cure for a deadly disease. The charity starts the year with cash of $775,000. Of this amount, unrestricted net assets total $425,000, temporarily restricted net assets total $225,000, and permanently restricted net assets total $125,000. Within the temporarily restricted net assets, the entity...
My java program will not compile. I receive the following error; Test.java:9: error: incompatible types: int[]...
My java program will not compile. I receive the following error; Test.java:9: error: incompatible types: int[] cannot be converted to int int size = new int [start]; //Java Program import java.util.Scanner; public class Test{ public static void main(String []args) { int start, num; System.out.println("Enter the number of elements in a array : "); start = STDIN_SCANNER.nextInt(); int size = new int [start]; System.out.println("Enter the elements of array where last element must be '0' : "); for(int i = 0; i...
So, I have this Matlab program that I have made for a lab, and despite having...
So, I have this Matlab program that I have made for a lab, and despite having different frequencies, when I go to plot them, the graphs look exactly the same. Can someone tell me why that is? I also need to know how to determine the digital frequencies(rad/sec) and how many samples per period of both of the waves? Thank you Code: N = 100; % Total number of time domain samples in simulation. A1 = 1; % Amplitude of...
This seems like to many cans to the company, so they test 100 and find that...
This seems like to many cans to the company, so they test 100 and find that 62 have 12 oz or more. Construct a 90% confidence interval for the proportion of cans that have at least 12 oz of cola. What is the margin of error for this interval? Round your answer to 4 decimal places. What is the lower bound of this interval? Round your answer to 4 decimal places. What is the upper bound of this interval? Round...
hey I have this program written in c++ and I have a problem with if statement...
hey I have this program written in c++ and I have a problem with if statement {} brackets and I was wondering if someone can fix it. //Name: Group1_QueueImplementation.cpp //made by ibrahem alrefai //programming project one part 4 //group members: Mohammad Bayat, Seungmin Baek,Ibrahem Alrefai #include <iostream> #include<stdlib.h> using namespace std; struct node { string data; struct node* next; }; struct node* front = NULL; struct node* rear = NULL; struct node* temp; void Insert() {     string val;    ...
I have one error and it encounters my split array and it should output true or...
I have one error and it encounters my split array and it should output true or false public class Main { private static int[] freq; static boolean doubleOrNothing(int[] array, int size, int i) {    if (size <= 1)    return false; if (2 * array[i] == array[i+1]) return true; return doubleOrNothing(array, size - 1, i++); } /** * * @param word * @param sep * * * @param count * @return */ public static String wordSeparator(String word, String sep,...
So I did the Milestone 1 already and it seems to be correct. But now i...
So I did the Milestone 1 already and it seems to be correct. But now i need to do the Milestone 2 Please help. Street Sweep MILESTONE 1 - Variable & Fixed Cost Exercise INSTRUCTIONS: Determine the per unit cost for each dog. Fill in the blanks to get the per unit cost and fixed cost of each service. Based on 5 grooms per day GROOMING Item Variable Costs Item Fixed Costs Shampoo $                      1.04 Groomer $              2,080.01 Clipper(s)                          ...
Here is my C++ program so far. Is there anyway I can make it display an...
Here is my C++ program so far. Is there anyway I can make it display an error if the user enters a float? Thanks #include <iostream> using namespace std; // Creating a constant for the number of integers in the array const int size = 10; int main() { // Assigning literals to the varibles int a[size]; int sum=0; float avg; // For loop that will reiterate until all 10 integers are entered by the user for(int i=0; i<size; i++)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT