need help with loops

I need help writing a loop either do while or while. one for entering in any amount of numbers to be individual set as num. then another loop for asking if they want to do it all over again.
i had some loops and they worked but not quite. so i removed them from my code here so sorry id the braces are off.
[code]

int main()
{
double num;
calc stats



( std::cout<<"enter a number or list of numbers when done enter type 'q'"<<std::endl;
std::cin>>num;


stats.setCount();
stats.setSum(num);
stats.setMean(num);
stats.setMin(num);
stats.setMax(num);
stats.setLast(num);


}

if(stats.getCount()==0)
{ std::cout<<"Sum = N/A Count = 0 Last= N/A Mean = N/A Min= N/A Max=N/A"<<std::endl;}
else
{
std::cout<<"sum is "<<stats.getSum()<<std::endl;
std::cout<<"mean is "<<stats.getMean()<<std::endl;
std::cout<<"last is "<< stats.getLast()<<std::endl;
std::cout<<"min is "<<stats.getMin()<<std::endl;
std::cout<<"max is "<<stats.getMax()<<std::endl;
std::cout<<"Count is "<<stats.getCount()<<std::endl;
}

}

Last edited on
Yes you need help, your main function ends at line 20.
At least format it and get what you have working...

your next problem is a logic one, your asking for a num, which can never = "q".
rethink your exit strategy and try again.
Duplicate:
http://www.cplusplus.com/forum/beginner/206875/

Please don't do this: it's a time waster.
Last edited on
I think I see what your doing now, the while loop or do while has to be inside your main function.

ps. I still don't like using q to exit even if it works :P

Topic archived. No new replies allowed.