#include <iostream>
usingnamespace std;
int main()
{
int actualage = 0, dogweight = 0;
cout << "Welcome to Tina's dog age calculator!" << endl;
cout << endl;
cout << "Please enter your dogs actual age (1-16): " << endl;
cin >> actualage;
if (actualage<1)
{
cout << "Invalid age. Please ener a number between 1 and 16. " << endl;
cin >> actualage;
}
elseif (actualage>16)
{
cout << "Invalid age. Please enter a number between 1 and 16. " << endl;
cin >> actualage;
}
if ((actualage>=1) && (actualage<=16))
{
cout << "Please enter your dogs weight: " << endl;
cin >> dogweight;
}
if ((dogweight>=20) && (dogweight<=50) && (dogweight<20) && (dogweight>50)
&& (actualage>=2) && (actualage<=16))
{
cout << "Your dogs age is " << 4*actualage+16 << endl;
}
elseif (actualage==1)
{
cout << "Your dogs age is " << actualage+14 << endl;
}
elseif ((dogweight>=21) && (dogweight<=50) && (actualage>=6) && (actualage<=16))
{
cout << "Your dogs weight is " << 4.5*actualage+16 << endl;
}
elseif ((dogweight>=50) && (actualage>=6) && (actualage<=16))
{
cout << "Your dogs age is " << 7.5*actualage << endl;
}
system ("pause");
return 0;
}
I'm having a problem getting my program to continue on after the user inputs their dog's weight. The console just closes instead of doing the calculations. It worked perfectly before I added the error messages. This is giving me such a headache.
Welcome to Tina's dog age calculator!
Please enter your dogs actual age (1-16):
1
Please enter your dogs weight:
2
Your dogs age is 15
Process finished with exit code 0
I have the problem narrowed down to one specific thing. For some reason if I take out the actualage>16 part, it works fine. But I need the error message to include that. The program is supposed to give an error message if the age entered is less than 1 or more than 16.