So I wrote my code out and when i compile it, it says that calcArea is not declared. Can somebody help explain the problem?
/****************************************************
Method: Calculate the area of a shape
Parameters: Length, Width
Return Value: Area
Preconditions: Width and Length must be greater than 0
Postconditions: Area will be true
****************************************************/
#include <iostream>
using namespace std;
int main(){
calcArea();
return 0;
}
void calcArea(){
//Declare variables
double length,width,area;
int a,b;
//Get input value
cout << "Please enter length: ";
cin >> length;
//Validate input
while (a == 0){
if (length <= 0){
cout << "invalid input. Try again." << endl;
}else{
a = 1;
}
}
//Get input value
cout << "Please enter width: ";
cin >> width;
//validate input
while(b==0){
if(width <= 0){
cout << "Invalid input, Try agian." << endl;
}else{
b = 1;
}
}
//calculate area
area = length * width;
cout <<"The area of the shape is :" << area;
}
Line 5: calcArea() is undefined. Because calcArea() follows main, you need a function prototype for it.
Line 14: a and b are uninitialized (garbage) variables.
Line 19: Unlikely your loop is going to execute. You're comparing a garbage variable in your while condition.
Line 31: ditto.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.