repeat function for averages

Hi,
I've been working on this program all week and I can't seem to figure out which repeat function I'm using and if I'm using it correctly.
I've tried the "while" function, and I've even used "repeat - until" and neither is working very well, or at all.
Here is my code, please advise on what I'm missing.
Thanks!


// Program: Demo7.cpp
// Author: Ari
// Date Written: 06/04/2008
// Purpose: Asks the user for the temperatures during an undetermined period of time
// and prints the average temperature for that period of time.
//
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;

// declare functions
void plot(string title, int number);

int main(int argc, char* argv[])
{
// declare variables
double temperature;
double counter;
double sum;

// Initialize variables
sum = 0;
counter = 0;

// Display the Program Title
cout << " Average Temperature Program\n";
cout << " ---------------------------\n";
// Ask the user for a temperature.
cout << "Enter the degrees Fahrenheit or -99 to quit: ";
cin >> temperature;

// Repeat the following instructions while age is not -99.
repeat (temperature != -99);
{
// Increment the count for the proper age group
sum = sum + temperature;
counter = counter ++;

// Ask for another temperature to repeat the loop
cout << "Enter the degrees Fahrenheit or -99 to quit: ";
cin >> temperature;
}


// display the report
cout << endl;
cout << "The average temp is: " << temperature << endl;

return 0;
}

Hi

Put the code that is to be repeated into this:
1
2
3
4
5
6
7
do
{

// enter your code here. It is sufficient to ask for temperature for the first 
// time in here

}while(!(int(temperature+0.1)==-99);


I am not definiely sure but a double is never the exact representation of an integer. So, a double of -99 might actually be -99,000.000.000.000.000.000.001 or so which obviously does not equal -99.

int main
Last edited on
awesome, thanks!
Topic archived. No new replies allowed.