Well, I'm very new to programming and I'm stuck on an assignment...
I'm supposed to make a program that involves creating a while loop and if-else statements. Unfortunately, I'm stuck. This is what I have so far.
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
char response;
cout <<"Animal Classifier" << endl;
cout << endl;
cout <<"Does the animal have backbones (Y/N)?" << endl;
cin >> response;
cout << endl;
if (response == 'Y')
{
cout << "The animal is a Vertebrate. Let's continue..." << endl;
}
else if (response == 'N')
{
cout << "The animal is an Insect." << endl;
}
cout << "Does the animal's body feel cold (Y/N)?" << endl;
cin >> response;
cout << endl;
if (response == 'N')
{
cout << "The animal is Warm-blooded. Let's continue..." << endl;
}
else if (response == 'Y')
{
cout << "The animal is a Reptile." << endl;
cout << endl;
}
cout << "Can it fly (Y/N)?" << endl;
cout << endl;
cin >> response;
if (response == 'Y')
{
cout << "The animal is a Bird." << endl;
cout << endl;
}
else if (response == 'N')
{
cout << "The animal is a Mammal." << endl;
cout << endl;
}
}
system("Pause")
return 0;
My question is....how do I make it so that when it DOES determine the type of animal it is, that it would loop around to the beginning. I will eventually cout<<"Would you like to start over?" so that it loops around, but I'm confused.
Please don't exactly tell me how, but if you can give me an example, that would be great. I think these are what is called a Nested If-Else?