8.9k views
2 votes
I would like assistance on writing a c++ program without using double. Thank you

I would like assistance on writing a c++ program without using double. Thank you-example-1
I would like assistance on writing a c++ program without using double. Thank you-example-1
I would like assistance on writing a c++ program without using double. Thank you-example-2
User Suken Shah
by
8.1k points

1 Answer

3 votes

Here is the corrected code:

function convertTime() {

let hours, minutes, ampm;

let military = prompt("Enter military time (hh:mm):");

// Verify input is a valid military time

if (!/^\d{2}:\d{2}$/.test(military)) {

alert(military + " is not a valid time.");

return;

}

// Parse hours and minutes

hours = parseInt(military.split(":")[0]);

minutes = parseInt(military.split(":")[1]);

// Convert to 12-hour format

if (hours == 0) {

hours = 12;

ampm = "AM";

} else if (hours < 12) {

ampm = "AM";

} else if (hours == 12) {

ampm = "PM";

} else {

hours = hours - 12;

ampm = "PM";

}

// Output the converted time

let standard = hours.toString().padStart(2, "0") + ":" + minutes.toString().padStart(2, "0") + " " + ampm;

alert("Standard time: " + standard);

// Ask if the user wants to convert another time

let repeat = prompt("Would you like to convert another time? (y/n)").toLowerCase();

if (repeat == "y") {

convertTime();

}

}

convertTime();

User Momro
by
7.9k points