← Back

30. πŸ† The Ultimate I/O Challenge - Complete Analytics

Challenge ⭐ FINAL BOSS

🎯 THE ULTIMATE CHALLENGE

Congratulations on reaching Question #30! This is THE ULTIMATE CHALLENGE that combines EVERYTHING you've learned from Questions 1-29. Are you ready? πŸš€

Problem: Life & Fitness Analytics Dashboard
Create a comprehensive analytics report that takes multiple inputs and produces a beautifully formatted output combining ALL Basic I/O concepts!

Input Format (5 values on separate lines):
Line 1: Total days lived (integer)
Line 2: Current weight in kg (decimal)
Line 3: Target weight in kg (decimal)
Line 4: Distance run today in meters (integer)
Line 5: Workout duration in seconds (integer)
Output Format (Multi-line formatted report):
=== LIFE ANALYTICS DASHBOARD ===
Age: XX years, YY months, ZZ days
Total Time Lived: HHHHHH:HH:MM:SS

=== FITNESS METRICS ===
Current Weight: XX.XX kg
Target Weight: XX.XX kg
Weight Difference: XX.XX kg (to gain/to lose)
Distance Today: X.XX km
Workout Time: HH:MM:SS
Calories Burned: XXXX cal
Constraints:
1 ≀ days ≀ 50000
1.0 ≀ weight ≀ 500.0
1 ≀ meters ≀ 100000
1 ≀ seconds ≀ 86400

Formulas:
β€’ 1 year = 365 days, 1 month = 30 days
β€’ Calories = distance_in_km Γ— 65
β€’ "to gain" if current < target, else "to lose"
Sample Input 1:
8520
75.5
70.0
5000
1800
Sample Output 1:
=== LIFE ANALYTICS DASHBOARD ===
Age: 23 years, 4 months, 0 days
Total Time Lived: 204480:00:00:00

=== FITNESS METRICS ===
Current Weight: 75.50 kg
Target Weight: 70.00 kg
Weight Difference: 5.50 kg to lose
Distance Today: 5.00 km
Workout Time: 00:30:00
Calories Burned: 325 cal
Sample Input 2:
10950
65.0
72.5
8250
3665
Sample Output 2:
=== LIFE ANALYTICS DASHBOARD ===
Age: 30 years, 0 months, 0 days
Total Time Lived: 262800:00:00:00

=== FITNESS METRICS ===
Current Weight: 65.00 kg
Target Weight: 72.50 kg
Weight Difference: 7.50 kg to gain
Distance Today: 8.25 km
Workout Time: 01:01:05
Calories Burned: 536 cal
πŸ† THE ULTIMATE CHALLENGE: All 29 Concepts Combined!

What Makes This Question Special?

This is NOT just another questionβ€”it's a MASTERPIECE that tests your mastery of EVERY SINGLE CONCEPT from the entire Basic I/O section! If you can solve this, you've truly conquered Basic I/O! πŸ’ͺ

πŸŽ“ Complete Concept Checklist (All 29 Questions!)

#1-5
Basic I/O & Escape Sequences
#6-8
Variables & Input
#9-19
Formatting (setw, setprecision, setfill)
#20
Multiple Inputs & Long Long
#21,28
abs() & cmath Library
#22
Decimal Multiplication
#23
Division & Type Casting
#24-25
Swap Algorithms
#26
Mathematical Logic
#27
Time Conversion (sec→HH:MM:SS)
#29
Days Decomposition

🧩 Concepts Used in This Challenge

Concept From Question(s) Usage in Challenge
Multiple Inputs #6, #20 5 different input values
Long Long Type #20 Large hour calculations
Decimal Operations #22 Weight & distance calculations
Type Casting #23 Integer to double conversions
abs() Function #21, #28 Weight difference calculation
Division & Modulo #27, #29 Time & age decomposition
fixed & setprecision #13, #22 Weight & distance formatting
setfill & setw #9, #27 Time format padding (00:30:00)
Mathematical Logic #26 Conditional text without if-else
String Output #1-5 Dashboard headers & labels

πŸ“Š Step-by-Step Solution Breakdown

πŸ“Œ Part 1: Age Calculation (Days β†’ Years, Months, Days)
// Input: 8520 days

// Extract years (365 days = 1 year)
int years = days / 365;
// 8520 / 365 = 23 years

days = days % 365;
// 8520 % 365 = 120 days remaining

// Extract months (30 days = 1 month)
int months = days / 30;
// 120 / 30 = 4 months

days = days % 30;
// 120 % 30 = 0 days

// Result: 23 years, 4 months, 0 days βœ“
πŸ“Œ Part 2: Total Time Lived (Days β†’ Hours)
// Input: 8520 days total

// Convert days to hours
long long total_hours = originalDays * 24;
// 8520 Γ— 24 = 204,480 hours

// Format: 204480:00:00:00
// (hours:minutes:seconds) - all zeros since exact days
πŸ“Œ Part 3: Weight Difference (abs + Logic)
// Inputs: current=75.5, target=70.0

double diff = abs(current - target);
// abs(75.5 - 70.0) = abs(5.5) = 5.50

// Determine gain or lose (without if-else!)
// If current < target: "to gain"
// If current >= target: "to lose"

// Mathematical approach from Q#26!
string status = (current < target) ? "to gain" : "to lose";
// For 75.5 vs 70.0: "to lose" βœ“
πŸ“Œ Part 4: Distance Conversion (Type Casting)
// Input: 5000 meters

double km = static_cast<double>(meters) / 1000.0;
// static_cast(5000) / 1000.0 = 5.00 km

// Format with 2 decimal places
cout << fixed << setprecision(2) << km;
// Output: 5.00 km βœ“
πŸ“Œ Part 5: Workout Time (Seconds β†’ HH:MM:SS)
// Input: 1800 seconds

int hours = seconds / 3600;
// 1800 / 3600 = 0 hours

seconds = seconds % 3600;
// 1800 % 3600 = 1800 seconds

int mins = seconds / 60;
// 1800 / 60 = 30 minutes

seconds = seconds % 60;
// 1800 % 60 = 0 seconds

// Format: 00:30:00 (with leading zeros!)
cout << setfill('0') << setw(2) << hours << ":"
     << setw(2) << mins << ":"
     << setw(2) << seconds;
// Output: 00:30:00 βœ“
πŸ“Œ Part 6: Calories Calculation
// Formula: calories = distance_in_km Γ— 65

int calories = static_cast<int>(km * 65);
// static_cast(5.00 Γ— 65) = 325 calories

// Output as integer (no decimals)
cout << calories << " cal";
// Output: 325 cal βœ“

🎯 Complete Example Trace (Input 1)

πŸ“Œ Full Walkthrough:
// === INPUT ===
Days: 8520
Current Weight: 75.5 kg
Target Weight: 70.0 kg
Distance: 5000 meters
Workout: 1800 seconds

// === CALCULATIONS ===

// Age Breakdown:
Years: 8520/365 = 23, Remainder: 120
Months: 120/30 = 4, Remainder: 0
Days: 0

// Total Hours:
8520 Γ— 24 = 204480 hours

// Weight Difference:
abs(75.5 - 70.0) = 5.50 kg
75.5 > 70.0 β†’ "to lose"

// Distance:
5000/1000.0 = 5.00 km

// Workout Time:
1800 sec = 0 hours, 30 minutes, 0 seconds

// Calories:
5.00 Γ— 65 = 325 cal

// === OUTPUT ===
=== LIFE ANALYTICS DASHBOARD ===
Age: 23 years, 4 months, 0 days
Total Time Lived: 204480:00:00:00

=== FITNESS METRICS ===
Current Weight: 75.50 kg
Target Weight: 70.00 kg
Weight Difference: 5.50 kg to lose
Distance Today: 5.00 km
Workout Time: 00:30:00
Calories Burned: 325 cal

πŸ’‘ Key Programming Techniques Used

πŸ”§ Technical Skills Demonstrated
1. Multiple Variable Types: int, long long, double, string

2. Input Handling: Sequential cin for 5 different values

3. Type Conversions: static_cast<double>, static_cast<int>

4. Mathematical Operations: Division (/), Modulo (%), Multiplication (*)

5. Library Functions: abs() from cmath, setw/setprecision/setfill from iomanip

6. Output Formatting: fixed, setprecision(2), setfill('0'), setw(2)

7. String Manipulation: Concatenating text and variables

8. Conditional Logic: Ternary operator for "to gain"/"to lose"

9. Decomposition Algorithm: Breaking down units hierarchically

10. Precision Control: Exact formatting for professional output

πŸ… Why This is the PERFECT Final Challenge

πŸŽ“ Complete Mastery Test:

This single question combines:

βœ… ALL formatting techniques (setw, setprecision, setfill, fixed)
βœ… ALL mathematical operations (/, %, *, -, abs)
βœ… ALL conversion patterns (time, distance, units)
βœ… ALL data types (int, long long, double, string)
βœ… ALL I/O techniques (multiple inputs, formatted outputs)
βœ… ALL libraries (iostream, iomanip, cmath)

If you can solve this, you've MASTERED Basic I/O! πŸ†
πŸŽ‰ Congratulations on Completing All 30 Questions!

You've journeyed through 30 carefully crafted questions, from simple print statements to this complex analytics dashboard. You've learned not just syntax, but patterns, techniques, and problem-solving approaches that will serve you throughout your programming career!


Welcome to the elite group of developers who've conquered Basic I/O! You're now ready for the next chapter! πŸš€

πŸ’» Solution Code
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
    // Input variables
    int totalDays, meters, workoutSec;
    double currentWeight, targetWeight;
    
    cin >> totalDays >> currentWeight >> targetWeight 
        >> meters >> workoutSec;
    
    // Save original days for hour calculation
    int originalDays = totalDays;
    
    // === AGE CALCULATION ===
    int years = totalDays / 365;
    totalDays = totalDays % 365;
    
    int months = totalDays / 30;
    int days = totalDays % 30;
    
    // === TOTAL HOURS LIVED ===
    long long totalHours = originalDays * 24;
    
    // === WEIGHT DIFFERENCE ===
    double weightDiff = abs(currentWeight - targetWeight);
    string status = (currentWeight < targetWeight) 
                      ? "to gain" : "to lose";
    
    // === DISTANCE CONVERSION ===
    double km = static_cast<double>(meters) / 1000.0;
    
    // === WORKOUT TIME BREAKDOWN ===
    int hours = workoutSec / 3600;
    workoutSec = workoutSec % 3600;
    
    int mins = workoutSec / 60;
    int secs = workoutSec % 60;
    
    // === CALORIES CALCULATION ===
    int calories = static_cast<int>(km * 65);
    
    // === OUTPUT ===
    cout << "=== LIFE ANALYTICS DASHBOARD ===" << endl;
    cout << "Age: " << years << " years, " 
         << months << " months, " << days << " days" << endl;
    cout << "Total Time Lived: " << totalHours 
         << ":00:00:00" << endl;
    cout << endl;
    
    cout << "=== FITNESS METRICS ===" << endl;
    cout << fixed << setprecision(2);
    cout << "Current Weight: " << currentWeight << " kg" << endl;
    cout << "Target Weight: " << targetWeight << " kg" << endl;
    cout << "Weight Difference: " << weightDiff 
         << " kg " << status << endl;
    cout << "Distance Today: " << km << " km" << endl;
    
    cout << "Workout Time: " 
         << setfill('0') << setw(2) << hours << ":"
         << setw(2) << mins << ":"
         << setw(2) << secs << endl;
    
    cout << "Calories Burned: " << calories << " cal";
    
    return 0;
}