In: Computer Science
Here is my algorithm: Ask how much time they need to do the assignment(Total hours) Ask how many days are available Calculate hour per day needed Store time needed per day in a variable 2. How many hours per day are available Store hours available per day in a variable Ask user how much time is spent doing other things Calculate how much time is available per day 24- (# of hours not available) Display how much time is available per day Compare time available to time need per day to complete program If time available is greater than the time needed, Display message saying than they have enough time If time available is less than the time needed, Display message asking if the user wants, To try different values Display message saying that they do not have enough time Ask if the user wants to repeat with different values If yes, repeat End program.
Programming language used below: C++
Source Code:
#include <iostream>
using namespace std;
int main()
{
int total_hours, days_available, time_needed, time_spent, day_hour,
time_left;
string s;
do
{
cout << "\nHow much time do you need to do the assignment
(Total hours): ";
cin >> total_hours;
cout << "\nHow many days are available: ";
cin >> days_available;
time_needed = total_hours / days_available;
cout << "\nHow much time is spent doing other things:
";
cin >> time_spent;
day_hour = 24;
time_left = day_hour - time_spent;
cout << "\nHours available per day is: "<<time_left;
if(time_left > time_needed)
cout << "\n\nYou have enough time.";
else if(time_left < time_needed)
{
cout << "\n\nYou do not have enough time.";
cout << "\n\nDo you want to repeat with different values
(Enter Y or N): ";
cin >> s;
}
}while(s == "y" || s == "Y");
return 0;
}
You can refer below for the screenshots of output:
Case 1:
Case 2:
Case 3: