Skip to content

Commit 758de2b

Browse files
authored
Merge pull request #214 from murali-33011/trying
Added time conversion of decade and century
2 parents 364dbe2 + f1d688b commit 758de2b

File tree

2 files changed

+31
-28
lines changed
  • Playground
    • Avinash262718h/DurationConverter-Java-Avinash262718h
    • avijitj14/BMICalculator-Cpp-avijitj14

2 files changed

+31
-28
lines changed

Playground/Avinash262718h/DurationConverter-Java-Avinash262718h/Main.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33

44
public final class Main {
55
// Stores all conversion factors with 'seconds' as the base unit.
6-
private static final Map<String, Integer> map = Map.of(
7-
"year", 31557600,
8-
"month", 2629800, // Note: This is an average month
9-
"week", 604800,
10-
"day", 86400,
11-
"hour", 3600,
12-
"min", 60,
13-
"sec", 1
6+
private static final Map<String, Long> map = Map.of(
7+
"century", 3155760000L, //Long literal for large numbers 'L' suffix has been added [otherwise error arises]
8+
"decade", 315576000L,
9+
"year", 31557600L,
10+
"month", 2629800L, // Note: This is an average month
11+
"week", 604800L,
12+
"day", 86400L,
13+
"hour", 3600L,
14+
"min", 60L,
15+
"sec", 1L
1416
);
1517

1618
public static void main(String[] args)
@@ -21,7 +23,7 @@ public static void main(String[] args)
2123
{
2224

2325
System.out.println("=== Duration Converter ===");
24-
System.out.println("Supported units: year, month, week, day, hour, min, sec.");
26+
System.out.println("Supported units: century, decade, year, month, week, day, hour, min, sec.");
2527
System.out.println("Enter duration, from_unit, and to_unit (e.g., 2 hour min):");
2628
final long duration = sc.nextLong();
2729
final String from = sc.next().toLowerCase();
@@ -37,7 +39,7 @@ public static void main(String[] args)
3739
System.out.println(duration + " " + from + " = " + result + " " + to);
3840
} catch (Exception e)
3941
{
40-
System.err.println("Invalid input. Please enter a number followed by two units.");
42+
System.err.println("Invalid input. Please enter a number followed by two units as per given instruction.");
4143
}
4244
}
4345
}
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#include <iostream>
22
#include <iomanip>
3-
43
using namespace std;
54

5+
void determineBMI(float height, float weight)
6+
{
7+
//Calculate BMI
8+
float bmi = weight / (height * height);
9+
10+
//Determine BMI category
11+
if (bmi < 18.5)
12+
cout << "BMI: " << bmi << " (Underweight)" << endl;
13+
else if (bmi < 25)
14+
cout << "BMI: " << bmi << " (Normal weight)" << endl;
15+
else if (bmi < 30)
16+
cout << "BMI: " << bmi << " (Overweight)" << endl;
17+
else
18+
cout << "BMI: " << bmi << " (Obese)" << endl;
19+
}
20+
621
int main()
722
{
823
int weight;
@@ -16,22 +31,8 @@ int main()
1631
cout << "Enter height in metres:" << endl;
1732
cin >> height;
1833

19-
//Calculate BMI using formula
20-
bmi = weight/(height * height);
21-
22-
//Truncate to decimal places
23-
cout << fixed << setprecision(2);
24-
25-
//Output result and category
26-
if(bmi < 18.5)
27-
cout << "BMI:" << bmi << " " << "(Underweight)" << endl;
28-
29-
if(bmi >= 18.5 && bmi < 25)
30-
cout << "BMI:" << bmi << " " << "(Normal weight)" << endl;
31-
32-
if(bmi >= 25 && bmi < 30)
33-
cout << "BMI:" << bmi << " " << "(Overweight)" << endl;
34+
//Determine BMI category
35+
determineBMI(height, weight);
3436

35-
if(bmi >= 30)
36-
cout << "BMI:" << bmi << " " << "(Obese)" << endl;
37+
return 0;
3738
}

0 commit comments

Comments
 (0)