Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Programing Homework (Help Please)

tro44_1tro44_1 Member Posts: 1,819

Look at the following problems and identify

a) the output

b) the input

c) the procedure

 

3. Dew Drop Inn, has a different rate structure. Here a guest pays by the week (7 nights). The rate is reasonable - $350. per week. But the guest must always pay for an entire week even if he stays less than the full week. Thus, 4 nights would cost 350. as would 7. If a guest stays 8 nights then he must pay for 2 weeks….or 350 times 2. The tax is still 7.5% and the energy charge is 3.50 per night. . Write a program which will allow you to enter a guest's name and the number of nights he stayed at the Inn. Print an itemized bill which shows the cost for the room, the tax, the energy charge and the total tax.

 

Hint. Since you are entering the number of nights, you will have to convert that to weeks.

HINT: You might be considering "if" for this. (if nights>7 and nights<15, weeks = 2) DON'T DO THIS you would never be able to stop saying "if"….

Think about / which can be used to convert to weeks.

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

This is the problem I have above.

The trouble iam having is, how do I use the Night--to--Week conversion to find weekly prices, without using (<|> if/Then) statements?

This is confusing me. 

For example, if the person stayed in  the hotel for 6 days, ---- That would be 6/7 in weeks,

but if I mutiple 6/7 *350, it wont give me the correct weekly price, since that would be less then 350$.

I dont know how to round up numbers using (+ - * / < >) operators.



 

Comments

  • DekronDekron Member UncommonPosts: 7,359

    Just a simple direction - try whatever language's Date() object.

  • sephersepher Member Posts: 3,561

    Use the modulo operator.

    6 % 7 = x

    11 % 7 = y

    254 % 7 = z

    70 % 7 = a

    You'd get x = 6, y = 4, z = 2, a = 0 from the above. So modulo will always tell the number of days short of the last full week.

    So if there was a function you made that accepted an integer and did the following, it'd always pass you the number of days right back presuming you're working with integer types (whole numbers that truncate and not round decimal places, i.e. 3 / 2 = 1 and not 1.5 rounded up to 2)

    x = 6, y = 11, z = 254, a = 70

    ((x / 7) * 7) + (x % 7) = 6 days

    ((y / 7) * 7) + (y % 7) = 11 days

    ((z / 7) * 7) + (z % 7) = 254 days

    ((a / 7) * 7) + (a % 7) = 70 days

     

    'course, dividing and then multiplying by 7 seems redundant there, but its not given the way integers work, i.e. with the 254 days example, 254 / 7 = 36, 36 x 7 = 252. The truncation of decimal places there works to your benefit in giving you the number of days in a full week, and the last modulo operation will give you the number of days in the remaining week.

    That what you were looking for?

  • merlintalormerlintalor Newbie CommonPosts: 3
    The exact moments in favor of getting the idea across would be of the faithful moment as that would be quite convincing methodology representing every type of venture in question. The exacting grade of theme style, schedule of references, citing a scrutiny wrapping english homework solver, letterhead format, sage scrutinize stance and the genuine interest in the responsible for are the biggest factors as a remedy for success.

    The earliest constituent of the college investigate dissertation is the intellectual that is the particular share of the instrument and the puss to the world. It sine qua non be captivated feel interest in a great deal of ways for making the right amount of comments and accurate acutance of the aims and the exploit of the objectives of the paper. The complete skills or buying a custom the form to make unerring comments would originate a series of perspectives on the reader’s demeanor so that they are accomplished to pick out on things.

    The next to enter an introduction is the remarkably viewpoint of how to a postal card a scrutiny typescript and mentions the overall process in regard to getting the aims achieved in the paper. The foremost elements of the periodical must be evaluated and forced to be weakened down into sections so that they can adorn it as a share of the paper. The great breakdown of the introduction section would be free resume service writing perfectly distinguishable as it would upright highlight the elements of the paper.

    The contents point ought to rise as a tree fitted making the virtuous amount of comments and the basic disposition of the researcher for their planning and organizing ability. The tiniest breakdown arrangement on the whole capacity of the organ would be wholly distinguishable and would constitute the remarkably aspects that would be support to end the objectives.
  • LukeGrahamLukeGraham Newbie Posts: 0

    I think you should try the module operator because it is the only manual way to build your program but it's difficult because when we use the tools it will easily generate a program and when we talk about the module then it takes more work as compare to tools. But should not worry now because there are thousands of tools have been introduced in the market which may help you to generate a program which you want. Even now we can easily use the best essay writing help for our projects and work because of thousands of online sites on the internet. These online sites not only help you to complete your work but also help you to get good marks in the exams as well. So, we should visit these sites to get help in our projects.

  • jeff90jeff90 Newbie CommonPosts: 2
    I'm absolutely agree that you need to use the modulo operator, I think as a  hypothesis help it's the best way to do that script.
  • jeff90jeff90 Newbie CommonPosts: 2
    edited September 2019
    Right
  • BenCharleyBenCharley Newbie CommonPosts: 1
    edited October 2019
    Hi, I’m Ben Charley. I’m a writer living in Newark, New Jersey. I am a fan of technology, music, and writing. I’m also interested in causes and painting.
    ATT support phone number
     

  • CleffyCleffy Member RarePosts: 6,412
    edited October 2019
    This thread is too funny. Necro'd by spam bots. Easy programming 101 problem, and all the spam bots failed to give the proper support to contact.
    Wait while I call ATT and the Geek Squad to help me with this. Maybe I will get hypothesis help on this basic problem. Better yet, let me ask an English tutor they surely would know.

    BTW modulo won't work in this case. What useful info will you get from a modulo when all you need to do is divide by seven and round up?

    float unroundedWeeks = (days/7) + 0.5;
    int weeks = unroundedWeeks;

    With shader scripts, its best to avoid branching. So figuring out how to do something without using a Boolean operation is good practice.
    Post edited by Cleffy on
  • QuizzicalQuizzical Member LegendaryPosts: 25,353
    Cleffy said:
    This thread is too funny. Necro'd by spam bots. Easy programming 101 problem, and all the spam bots failed to give the proper support to contact.
    Wait while I call ATT and the Geek Squad to help me with this. Maybe I will get hypothesis help on this basic problem. Better yet, let me ask an English tutor they surely would know.

    BTW modulo won't work in this case. What useful info will you get from a modulo when all you need to do is divide by seven and round up?

    float unroundedWeeks = (days/7) + 0.5;
    int weeks = unroundedWeeks;

    With shader scripts, its best to avoid branching. So figuring out how to do something without using a Boolean operation is good practice.
    Careful, as if days is an integer (which it likely is), then that won't give you what you want.  For example, 6/7 will evaluate to 0, not 1 or 0.857143.

    Furthermore, taking an integer and adding 0.5, then casting the resulting float back to an integer, will likely only give you what you started with.  A cast customarily truncates, not rounds.  Some languages would want your cast to be more explicit than that when you go from a float to an int.

    If the goal is to round up rather than down, then something like:

    int weeks = (days + 6) / 7;

    will do it.  Alternatively, if you're willing to assume that the numbers aren't large enough for floating-point rounding issues to become a problem, you could get rid of the divide by saying:

    int weeks = (int)fma(days, 0.142857f, 0.99f);

    Making unnecessary assumptions like that might get you docked points in a class, though.

    And yes, I realize that the original poster hasn't come here in so long that the forum isn't sure when he was last active.
  • CleffyCleffy Member RarePosts: 6,412
    Good point on the much cleaner solution. For recasting to an int, some languages do round, some don't. I typically test to see if it casts as I expect if it's a language I am unfamiliar with. Before I posted I double checked with a search if the cast was sufficient since I know it can be finicky depending on the language.
  • JeffWilliams103JeffWilliams103 Newbie CommonPosts: 2
    edited February 2023
    Hi
    Post edited by JeffWilliams103 on
Sign In or Register to comment.