UAB – 2005: Problem 4: Push Ups with Blaze


At UAB football games, Blaze does push ups after each Blazer score. After the first Blazer touchdown (and point after), Blaze does 7 push ups. After the second touchdown and point after, the score is now 14 and Blaze does 14 push ups.

Write a program that calculates how many total push ups Blaze does during the whole game. Assume that only 7 point touchdowns (including the point after) occur. Prompt for the final score and print out how many push ups Blaze has done.

Example 1:
Enter final score: 21
Push ups: 42

Example 2:
Enter final score: 7
Push ups: 7


Enter final score: 0
Push ups: 0

Enter final score: 14
Push ups: 21

Enter final score: 28
Push ups: 70

Enter final score: 35
Push ups: 105

Enter final score: 42
Push ups: 147


// @BEGIN_OF_SOURCE_CODE

#include <cstdio>

using namespace std;

int main (int argc, char *argv [])
{
    int finalScore;
    printf ("Enter final score: ");
    scanf ("%d", &finalScore);
    
    int pushUps = 0;
    for ( int i = 7; i <= finalScore; i = i + 7 )
        pushUps = pushUps + i;
    
    printf ( "Push ups: %d\n", pushUps );
    
    return 0;
}

// @END_OF_SOURCE_CODE

Advertisements

4 thoughts on “UAB – 2005: Problem 4: Push Ups with Blaze

  1. this a typical beginner’s program for this problem:

    #include
    int main()
    {
    int score,i,pushup=0;
    printf(“please enter the final score: “);
    scanf(“%d”,&score);
    printf(“\n”);
    if(score%7==0){
    for(i=1;i<=score/7;i++){
    pushup=pushup+7*i;
    }
    }
    else{
    printf(" please enter a multiple of 7.\n");
    }
    printf("\n");
    printf("the total number of push-ups is %d",pushup);
    printf("\n");
    return 0;
    }

  2. I think I have this working in Golang:

    package main

    import (
    “fmt”
    )

    func main() {
    score := 21
    tally := tally(score)
    fmt.Println(tally)
    }

    func tally(score int) int {
    div := score / 7
    var hm int
    for div > 0 {
    hm += 7 * div
    div -= 1
    }
    return hm
    }

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