Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Sentinel Loop Question

Sentinel Loop Question

Scheduled Pinned Locked Moved C#
questionsaleshelptutorial
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JMOdom
    wrote on last edited by
    #1

    I am newbie at this, please try to be patient with me. :) In my class at school we have been trying out various loops in problems. The instructor calls the one we've been using a "Sentinel Loop". If there is another name for it I don't know what it is. :( :doh: I can get it to accept the input and also the stopping statement. I can even get the program to tell me the sales tax and shipping "on an individual input". The instructor wants to be able to input several figures and when the stopping statement is triggered, have the program show the total shipping cost and sales tax for all of the inputs together. I have placed the math parts between the two input statements, and also outside of the loop. My question is: "Do I need to put the math section into a method and if so where would I place the calling statement so that it would only work after the stop statement is triggered or would something else be even more appropriate?" :sigh: I have been beating my head against the wall for the last 10 days, and have not figured out an answer. I have tried everything I can think of. X| Can someone either please answer the question or at least steer me to the information on how to do this type of a problem. I would appreciate it greatly. This is the main body of my sentinel loop program. I can get it to work fine. using System; using System.Collections.Generic; using System.Text; namespace Exer4Chpt6 { class Program { static void Main() { string inValue = ""; double salesAmount = 0; double salesTax; double shipAmount = 0; double grdTotal; const double INTEREST_RATE = .07; double overAllTotal = 0; double totalShippingAmt = 0; double totalSalesTax = 0; Console.WriteLine("Enter as many different sales amounts "); Console.WriteLine("as you want. You will be shown the sales "); Console.WriteLine("amount, sales tax, shipping amount, and "); Console.WriteLine("the grand total. To Stop, enter"); Console.WriteLine(" -99"); Console.WriteLine(); Console.WriteLine("Please type in a sales amount."); inValue = Console.ReadLine(); // Priming read, input before loop while (inValue != "-99") { salesAmount = Convert.ToDouble(inValue); salesTax = salesAmount * INTEREST_RATE; Console.

    J 1 Reply Last reply
    0
    • J JMOdom

      I am newbie at this, please try to be patient with me. :) In my class at school we have been trying out various loops in problems. The instructor calls the one we've been using a "Sentinel Loop". If there is another name for it I don't know what it is. :( :doh: I can get it to accept the input and also the stopping statement. I can even get the program to tell me the sales tax and shipping "on an individual input". The instructor wants to be able to input several figures and when the stopping statement is triggered, have the program show the total shipping cost and sales tax for all of the inputs together. I have placed the math parts between the two input statements, and also outside of the loop. My question is: "Do I need to put the math section into a method and if so where would I place the calling statement so that it would only work after the stop statement is triggered or would something else be even more appropriate?" :sigh: I have been beating my head against the wall for the last 10 days, and have not figured out an answer. I have tried everything I can think of. X| Can someone either please answer the question or at least steer me to the information on how to do this type of a problem. I would appreciate it greatly. This is the main body of my sentinel loop program. I can get it to work fine. using System; using System.Collections.Generic; using System.Text; namespace Exer4Chpt6 { class Program { static void Main() { string inValue = ""; double salesAmount = 0; double salesTax; double shipAmount = 0; double grdTotal; const double INTEREST_RATE = .07; double overAllTotal = 0; double totalShippingAmt = 0; double totalSalesTax = 0; Console.WriteLine("Enter as many different sales amounts "); Console.WriteLine("as you want. You will be shown the sales "); Console.WriteLine("amount, sales tax, shipping amount, and "); Console.WriteLine("the grand total. To Stop, enter"); Console.WriteLine(" -99"); Console.WriteLine(); Console.WriteLine("Please type in a sales amount."); inValue = Console.ReadLine(); // Priming read, input before loop while (inValue != "-99") { salesAmount = Convert.ToDouble(inValue); salesTax = salesAmount * INTEREST_RATE; Console.

      J Offline
      J Offline
      JMOdom
      wrote on last edited by
      #2

      I was able to recheck on these type of loops and found a solution. By placing the math section after the final input I've got it to work correctly. I placed the math section in the spot shown below. :-D salesAmount = Convert.ToDouble(inValue); salesTax = salesAmount * INTEREST_RATE; Console.WriteLine("Please type in a sales amount."); inValue = Console.ReadLine(); // reassigns data in inValue //to check in loop } //START math section in this area. } :cool::rose:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups