I need to use try...catch so if the user enters more then 10 digits
Code:#include <iostream> int main( int argc, const char*argv ) { int numInput = 0, avgCount = 0, totalCount = 0; float average = 0; while( numInput != 99 ) { std::cout << "Enter a Number (Max 10 digits)(99 to Exit): "; std::cin >> numInput; if ( numInput != 99 ) { totalCount += numInput; avgCount += 1; } } try { if( avgCount == 0 ) { throw 0; } average = totalCount / avgCount; } catch(...) { std::cout << "Divide by Zero error" << std::endl; totalCount = 0; } std::cout << "Average of all Inputs: " << average << std::endl; system("pause"); return 0; }


Reply With Quote

Bookmarks