The problem here is that you are trying to print the length before taking an input.
The cout<<length
will print a garbage value since length hasn’t been assigned yet. Try this instead. Also don’t use using namespace std;
#include<iostream>
int main(){
int length;
std::cout << "Input length of a square in centimeter ";
std::cin >> length;
std::cout << length;
}
1
solved C++ declaring variable and console [closed]