dicission making example in c++
/*
Scenario
As you surely know, due to some astronomical reason, a year may be leap or common. The former is 366 days long while the latter is365 days.
Since the introduction of the Gregorian calendar (in 1582), the following rule is used to determine the kind of year:
• if the year number isn't divisible by 4, it is a common year;
• otherwise, if the year number isn't divisible by 100, it is a leap year;
• otherwise, if the year number isn't divisible by 400, it is a common year;
• otherwise, it is a leap year.
*/
#include <iostream>
using namespace std;
int main()
{
int year;
cout << "enter year ";
cin >> year;
if (year > 1582)
{
if (year % 4 != 0)
cout << "it is common year";
else if (year % 100 != 0)
{
cout << "it is a leap year";
}
else if (year % 400 != 0)
{
cout << "it is a common year";
}
else
{
cout << "not in Gregorian calender ";
}
}
}
code 2
#include <iostream>
#include <string>
using namespace std;
int main()
{
int system,x,y,ans ;
char metric, imperial;
float m,ft;
metric = '0';
imperial = '1';
m = 5;
ft = 4;
cout << "press 0 or 1 to choose your system (0 for metric and 1 for imperial)";
cin >> system;
cout << "value of x ";
cin >> x;
cout << "value of y ";
cin >> y;
if (system == metric)
{
cout << "metric system " << endl;
cout << "int&ft to m=";
ans = x * (39.77) + y / 3.281;
cout << "answer is = ", ans ;
}
else if (system ==imperial)
{
cout << "imperial system " << endl;
cout << "m to in&ft=";
ans = x / 39.77 + y * 3.281;
cout << "answer is = ", ans;
}
}
Comments
Post a Comment