How Many Weeks?


TCEA State Programming Contest
April 28, 2001

Problem 2.3 How Many Weeks?

General Statement: A town in Death Valley has a water tank that contains 10,000 gallons of water. If there is no rain, calculate the number of weeks the water will last for an input weekly water usage.

Input: The data set is on a single line. There are an unknown number of integers in the data set. The integer 0 is used to indicate the end of the data.

Output: Use all upper case letters. The output is to be formatted exactly like that for the sample output given below.

Assumptions: The weekly usage does not exceed 10,000 gallons. The 0 used to indicate the end of the data is not part of the data for the problem.

Discussion: Do not include the last week if the water remaining for that week is less than the weekly usage amount.

Sample Input: 1750 1000 4325 0

Sample Output:
1750 GALLONS PER WEEK WILL LAST 5 WEEKS
1000 GALLONS PER WEEK WILL LAST 10 WEEKS
4325 GALLONS PER WEEK WILL LAST 2 WEEKS

Solutions:


#include <stdio.h>

int main ()
{
    int water_usage;

    while ( scanf ("%d", &water_usage) && water_usage ) {

        printf ("%d GALLONS PER WEEK WILL LAST %d WEEKS\n", water_usage, 10000 / water_usage );
    }

    return 0;
}


Advertisements

One thought on “How Many Weeks?

  1. #include
    int main(){
    int weekly_usage;
    int i,x;
    int duration=0;
    printf(“please enter the number of inputs: “);
    scanf(“%d”,&x);
    printf(“\n”);
    for(i=1;i<=x;i++){
    duration=0;
    printf("please enter the weekly usage: ");
    scanf("%d",&weekly_usage);
    printf("\n");
    printf("the number of weeks for this weekly usage is: %d\n",duration=10000/weekly_usage);
    printf("\n");
    }
    return 0;
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s