#include <iostream>
int main()
{
using namespace std;
int carrots = 1;
if (carrots < 5)
{
cout << "Let's buy new carrots!" << endl;
//buy new carrots
}
else
{
cout << "No need to buy some carrots!" << endl;
// no need to buy carrots.
}
return 0;
}
조건이 여러개 일 때
#include <iostream>
int main()
{
using namespace std;
int carrots = 7;
if (carrots < 5)
{
cout << "Let's buy new carrots!" << endl;
//buy new carrots
}
else if (carrots < 10)
{
cout << "Ummmm....." << endl;
}
else
{
cout << "No need to buy some carrots!" << endl;
// no need to buy carrots.
}
return 0;
}
과제
#include <iostream>
int main() {
using namespace std;
int year;
int month;
int day;
int birth;
cout << "몇년도에 태어나셨나요? " << endl;
cin >> year;
cout << "몇월에 태어나셨나요? " << endl;
cin >> month;
cout << "며칠에 태어나셨나요? " << endl;
cin >> day;
cout << year << "년" << month << "월" << day << "생이군요!" << endl;
if (year < 2004)
{
cout << " 출입가능 " << endl;
}
else
{
cout << " 출입금지 " << endl;
}