Valera (valera) wrote,
Valera
valera

  • Music:

averages, arrays, and lack of sleep

i've gotten myself to a much advanced level of stupidity!
doing my programming hw.
problem: write a prog that takes in several integers and outputs their average upon completion (which is activated by entering 9999.

so i write a loop to take in those integers, and start collecting them into an array! then i get to thinking that the prof prolly won't like it because we haven't done arrays in class yet (aha, it's that slow), then i wonder how i'm gonna control the size of the array, doing dynamic sizing would really piss the prof off. after 10 minutes of this mind fucking i realize that i'm an idiot, write this post, and just add all the entered values into one variable, deviding it by the counter afterwards.

code:
/*
   # 2.41: Write a program that calculates and prints the average of several integers. Assume the last value read is the sentinel 9999.
*/

#include <iostream>
using namespace std;

int main() {
        int sentinel = 0, counter = 0, total = 0;

        while(sentinel != 9999) {
                cout << "Enter int #" << (counter + 1) << "(9999 to quit): ";
                cin >> sentinel;
                if(sentinel != 9999) {
                        total += sentinel;
                        ++counter;
                }
        }

        if(!counter) {
                cout << "Sorry to see you go so soon..." << endl;
        } else {
                cout << "Average: " << static_cast<float>(total) / counter <<
                        endl;
        }

        return 0;
}



Other than that... Spoke to Becky yesterday around 5:30 from work. We decided to watch a movie in the after hours. So i went home, shaved (sidenote: I'm growing some sorta sideburns. Maybe I'll have photos at some point), and left the house at 7 to go to brighton and pick her up from work. Just before getting there she called me and said that she'd be stuck at work until 11 or so and that unfortunately our plans for the night are cancelled.

Called Anna and Boris to hang out with them (they live 5 min away from where I was driving at the moment). Went over to Anna's house and played scrabble with her (lost by 1 point! she kicked us out[around 12:30] :( )
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 10 comments