online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <iomanip> #include <vector> double avg(const std::vector<std::vector<int>> &arr) { int sum=0; for(const std::vector<int> &tempRow: arr) { for(const int &tempCol: tempRow){ sum+=tempCol; //std::cout<<sum; } } return (static_cast<double>(sum)/(arr.at(0).size() * arr.size())); } int main() { int row, col; std::cout<<"How many rows does the 2D array have: "; std::cin>>row; std::cout<<"How many columns does the 2D array have: "; std::cin>>col; //create a 2D vector instead of array std::vector<std::vector<int>> ar(row, std::vector<int>(col)); std::cout<<"Enter the 2D array elements below : \n"; for(auto &tempRow: ar){ for(auto &tempCol: tempRow){ std::cin>>tempCol; } } std::cout<<"\n Array is: \n"; for(auto &tempRow: ar) { for(auto &tempCol: tempRow) std::cout<<std::setw(6)<<tempCol; std::cout<<std::endl; } std::cout<<"\nAverage of all the elements of the given D array is: \n"; std::cout<<avg(ar); return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue