Control Break Logic

Discussion in 'Software' started by collegestudent2, Nov 27, 2009.

  1. collegestudent2

    collegestudent2 Private E-2

    The problem of the day:

    Brewster's Used Car's, Inc. employ several sales people. Brewster, the owner of the company, has provided a file that contains sales records for each salesperson for the past month. Each record in the file contains the following two fields: The salesperson's ID number, as an integer and the amount of a sale, as a real number. The records are already sorted by salesperson ID. Brewster wants you to design a program that prints a sales report. The report should show each salesperson's sales and the total sales for that salesperson. The report should also show the total sales for all salespeople for the month.

    This is what I came up with as a response. Once again thank you in advance, Im just looking for a little conformation that I'm headed in the right direction because I only have one person I can talk to about this class.



    Module main ()
    // Print The Brewster’s Report Header.
    Call printStore()

    //Print The Brewster’s Report Details.
    Call printFinances()
    End Module

    // The printStore Module Prints The Brewster’s Report Header.
    Module printStore()
    Print “Brewster’s Used Cars, Inc.”
    Print “Sales Report”
    Print
    Print “Sales Person ID Sales Amount”
    Print “==================================”
    End Module

    // The printFinances Module Prints The Sales Report Information.
    Module printFinances ()

    //Variables For The Fields
    Declare Integer salesPersonID
    Declare Real saleAmount

    // Accumulator Variables
    Declare Real salesPersonTotal = 0
    Declare Real total = 0


    // A Variable To Use In The Control Break Logic
    Declare Integer currentID

    //Declare An Input File And Open It.
    Declare InputFile salesFile
    Open salesFile “sales.dat”

    // Read The First Record.
    Read salesFile salesPersonID, salesAmount

    //Save The Salesperson ID Number.
    Set currentID = salesPersonID

    //Print The Report Details.
    While NOT eof (salesFile)

    // Check The Salesperson ID Field To See If It Has Changed.
    If salesPersonID != currentID Then

    // Print The Total For Each Salesperson, Followed By A Blank Line.
    Print “Total sales for this salesperson: “,
    currencyFormat (salesPersonTotal)
    Print

    // Save The Next Salesperson’s ID Number.
    Set currentID = salesPersonID

    // Reset The Salesperson Accumulator.
    Set salesPersonTotal = 0
    End If

    //Print The Data For The Sales Report.
    Print salesPersonID, Tab, currencyFormat (salesAmount)

    // Update The Accumulators.
    Set salesPersonTotal = salesPersonTotal + salesAmount
    Set total = total + salesAmount

    // Read The Next Record.
    Read salesFile, salesPersonID, salesAmount
    End While

    // Print The Total For The Last Salesperson.
    Print “Total sales for this salesperson: “,
    currencyFormat (salesPersonTotal)

    // Print The Total Of All Sales.
    Print “Total of all sales: “,
    currencyFormat(total)

    //Close The File.
    Close salesFile
    End Module
     
    Last edited: Nov 27, 2009
  2. JJJIrish05

    JJJIrish05 Sergeant

    Please indent your code and use the [ C O D E ] [ / C O D E ] tags, it's really hard to follow since you aren't using brackets, semi colons, and it isn't indented
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds