So I am trying to finish an assignment which involves the user to enter the original video time as a floating point value then have the user enter the playback speed factor, again as a floating point value. Then once I have this information I will need to convert the original time into seconds then, use the factor to determine what the new video time would be. Display the results in seconds. (Note that you must use an integer data type to store the new video time.) Now as I already have mass majority of this code already done I'm confused on when it comes to converting part of the code.
using System;
class Program
{
public static void Main(string[] args)
{
float og_videotime, playback_speed;
int og_videotime_seconds, new_videotime_seconds;
Console.WriteLine("[Fast-Forward]");
Console.Write("What is the original video time? ");
og_videotime = float.Parse(Console.ReadLine());
Console.Write("What is the playback speed factor? ");
playback_speed = float.Parse(Console.ReadLine());
// convert time to seconds
og_videotime_seconds = (int)(og_videotime * 60);
new_videotime_seconds = (int)(og_videotime_seconds / playback_speed);
// space
Console.WriteLine();
// output
Console.WriteLine("The new video time would be {0} second(s).", new_videotime_seconds);
Console.WriteLine("That saves you {0} second(s) from the original video speed.", og_videotime_seconds - new_videotime_seconds);
}
}
A sample output provided: [Fast-Forward] What is the original video time? 2.30 What is the playback speed factor? 2 The new video time would be 75 second(s). That saves you 75 second(s) from the original video speed.
Another Sample output: [Fast-Forward] What is the original video time? 3.59 What is the playback speed factor? 1.75 The new video time would be 136 second(s). That saves you 103 second(s) from the original video speed.
But my code produces: [Fast-Forward] What is the original video time? 3.59 What is the playback speed factor? 1.75
The new video time would be 122 second(s). That saves you 93 second(s) from the original video speed.
Math for the first sample: Now when I do the exact same number both my new video time and save seconds come out to be 69 instead of 75 which is where my confusion comes in. If I am correct to receive 75 I would have to do 2 * 60 = 120 then 120 30 = 150 then 150 / 2 to get 75 but I don't understand how I can break this down.
Thank you for all the help!
CodePudding user response:
just edit this line:
You are multiplying 2.30 by 60
and the result is 138
. Not 150
// og_videotime_seconds = (int)(og_videotime * 60);
var temp = og_videotime.ToString("N2").Split('.');
og_videotime_seconds = int.Parse(temp[0]) * 60 int.Parse(temp[1]);
You can multiply the number part of og_videotime
by 60
and add it to the decimal part
.
CodePudding user response:
You can use the following code: I just made a small change
class Program
{
static void Main(string[] args)
{
float og_videotime, playback_speed;
int og_videotime_seconds, new_videotime_seconds;
Console.WriteLine("[Fast-Forward]");
Console.Write("What is the original video time? ");
og_videotime = float.Parse(Console.ReadLine());
Console.Write("What is the playback speed factor? ");
playback_speed = float.Parse(Console.ReadLine());
// convert time to seconds
var FloatToMin =og_videotime.ToString().Split('.');
og_videotime_seconds = (int.Parse(FloatToMin[0]) * 60) int.Parse(FloatToMin[1]);
new_videotime_seconds = (int)(og_videotime_seconds / playback_speed);
// space
Console.WriteLine();
// output
Console.WriteLine("The new video time would be {0} second(s).", new_videotime_seconds);
Console.WriteLine("That saves you {0} second(s) from the original video speed.", og_videotime_seconds - new_videotime_seconds);
}
}
My mother says: the mountain that can be seen is not far away, don't stop trying