[学习笔记]C++17学习第6天
本帖最后由 mdl2999_52pj 于 2021-5-18 10:00 编辑```
# include <iostream>
// c++17
using namespace std;
int main()
{
int age;
cout << "Please enter your age in years: ";
cin >> age;
int income;
cout << "Please enter your income in dollars: ";
cin >> income;
int balance;
cout << "Please enter your current balance in dollars: ";
cin >> balance;
if (age >= 21 && (income > 2'5000 || balance > 10'0000))
{
int loan{};
if (2*income < balance/2)
loan = 2*income;
else
loan = balance/2;
cout << "\nYou can borrow up to $" << loan << endl;
}
else
{
cout << "\nUnfortunately, you don't qualify for a loan.\n";
}
}
```
```
# include <iostream>
// c++17
using namespace std;
int main()
{
int brown,white;
cout << "How many brown mice do you have? ";
cin >> brown;
cout << "How many white mice do you have? ";
cin >> white;
int mice{brown+white};
cout << "You have " << mice << (mice>1?" mouse ": " mice ") << "in total.\n";
}
```
```
# include <iostream>
// c++17
using namespace std;
int main()
{
int choice{};
cout << "Your electronic recipe book is at service.\n";
cout << "You can choose from the following deliciouse dishes:\n";
cout << "1 Boiled eggs\n"
<<"2 Fired eggs\n"
<<"3 Scrambled eggs\n"
<<"4 Coddled eggs\n\n"
<<"Enter your selection number: ";
cin >> choice;
switch(choice)
{
case 1:
cout << "Boil some eggs.\n";
break;
case 2:
cout << "Fry some eggs.\n";
break;
case 3:
cout << "Scramble some eggs.\n";
break;
case 4:
cout << "Coddle some eggs.\n";
break;
default:
cout << "You entered a wrong number.";
break;
}
}
```
```
# include <iostream>
# include <cctype>
// c++17
using namespace std;
int main()
{
char letter{};
cout << "Enter a letter: ";
cin >> letter;
if (isalpha(letter))
{
switch(letter)
{
case 'A': case 'a':
case 'E': case 'e':
case 'I': case 'i':
case 'O': case 'o':
case 'U': case 'u':
cout << "You entered a vowel.\n";
break;
default:
cout << "you entered a consonant.\n";
break;
}
}
else
{
cout << "You didn't enter a letter.\n";
}
}
```
页:
[1]