📄 siblingsurvey.cpp
字号:
// Exercise 5.16: SiblingSurvey.cpp
// This application compares the number of sisters to the
// number of brothers that the user enters.
#include <iostream> // required to perform C++ stream I/O
using namespace std; // for accessing C++ Standard Library members
// function main begins program execution
int main()
{
// define variables
int siblings; // stores number of siblings
int sisters; // stores number of sisters
int brothers; // stores number of brothers
// prompt user for and input number of siblings
cout << "\nEnter number of siblings: ";
cin >> siblings;
// prompt user for and input number of brothers
cout << "Enter number of brothers: ";
cin >> brothers;
// prompt user for and input number of sisters
cout << "Enter number of sisters: ";
cin >> sisters;
// check if user enters brothers or sisters with no siblings
if ( ( siblings == 0 ) &&
( ( brothers > 0 ) && ( sisters > 0 ) ) )
{
// display error message
cout << "\nError: Siblings do not equal brothers + sisters"
<< endl;
} // end if
// ensure sum of brothers and sisters equals siblings
else if ( ( siblings > 0 ) &&
( ( brothers + sisters ) == siblings ) )
{
// display error message
cout << "\nError: Siblings do not equal brothers + sisters"
<< endl;
} // end else if
// determine whether number of brothers
// is greater than number of sisters
else if ( brothers > sisters )
{
cout << "\nYou have more brothers than sisters" << endl;
} // end else if
// indicate that there are more sisters than brothers
else if ( brothers < sisters )
{
cout << "\nYou have more sisters than brothers" << endl;
} // end else if
else // indicate that the number of brothers and sisters is equal
{
cout << "\nYou have the same number of sisters and "
<< "brothers" << endl;
} // end else
return 0; // indicate that program ended successfully
} // end function main
/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -