array


// Write a fragment of code that reads in integers from standard input, until end-of-file and sends their (floating point) average to standard output. If no numbers are input, the message “no values to average” is printed instead (while loops, end-of-file processing, mixed-mode arithmetic, basic conditional)

//I think it is asking to write it without a loop but
this is what i have so far:

#include <iostream>
using namespace std;

int main()
{
const int size=5;
double num[size];

for(int i=0;i<size;i++)
{
cout<<"type in values: ";
if(cin.get())//<~dont know how to check if input is a number
cout<<"novalues to average"<<endl;
else
cin>>num[i];
}
for(int i=0;i<size;i++)
cout<<num[i]<<" ";

cin.get();
cin.get();

return 0;
}
cin.get inputs a single character, not integer or float. hint: each character has a decimal value. once you store them into your integer array, you will be able to just do arithmetic.
Topic archived. No new replies allowed.