So heres my code. It seems to me that cin.good doesn't work in Xcode. Any help would be wonderful.
Code:
#include <iostream>
#include <ctype.h>
usingnamespace std;
void Pyramid(int base, int height){
float pyramid;
pyramid=(1.0/3)*base*height;
cout<<"The volume is "<<pyramid<<"\n";
}
int main() {
int base, height;
for (int x=0; x==0[IMG]http://linustechtips.com/main/public/style_emoticons/default/wink.png[/IMG] {
cout << "Enter the base then the height.\n";
cin>>base;
if (!cin.good()) {
cin.clear();
cin.sync();
cout<<"Please enter numbers higher than 0\n";
cin>>base;
}
cin>>height;
if (!cin.good()) {
cin.clear();
cin.sync();
cout<<"Please enter numbers higher than 0\n";
cin>>height;
}
if (base>0 && height>0)
{
Pyramid(base,height);
x=1;
}
if (base<=0||height<=0) {
cout<<"Please enter numbers higher than 0\n";
cin>>base>>height;
}
}
return 0;
}
Last edited by a moderator: