C problem

Started by
10 comments, last by MaulingMonkey 18 years, 7 months ago
How about this:

std::vector<int> peices;int n_peices, peice_length, remaining_length;/* Calculate number of peices needed */n_peices = (total_length_required + 60) / 61;/* Calculate shortest length - longest one will be this +1 */peice_length = total_length_required / n_peices;remaining_length = total_length_required % n_peices;/* Insert short and long peices */peices.insert(peices.end(), remaining_length, peice_length+1);peices.insert(peices.end(), n_peices - remaining_length, peice_length);

Advertisement
Quote:Original post by Xloner12
Well I didnt mean to sound harsh. Its just that its not for home work. So my appoliges if it did.


Didn't sound harsh to me :-). You've got a good enough explaination I'm willing to assume it isn't home work, especially considering how simple this is with a little explaination, and that you'll be flunking your course anyways if this IS a homework problem, most likely :-).

unsigned int segments_of_neon = 1;double length_of_individual_segment_of_neon = initial_feet_of_neon;/* while each individual piece of neon is too big... */while ( length_of_individual_segment_of_neon > 61.0 ) {    /* ...divide each one in two! */    length_of_individual_segment_of_neon /= 2;    /* This also gives us twice as many segments: */    segments_of_neon *= 2;}/* We could also calculate the total number of segments after the fact: */double segments_of_neon =  initial_feet_of_neon / length_of_individual_segment_of_neon ;


[Edited by - MaulingMonkey on September 11, 2005 12:22:45 AM]

This topic is closed to new replies.

Advertisement