-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion1.cpp
More file actions
30 lines (25 loc) · 908 Bytes
/
question1.cpp
File metadata and controls
30 lines (25 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* Write a program that asks the user for the number of days.
* The program then prints out the number of seconds in the number of days given.
*/
#include <iostream>
int main() {
// Declaration of variables
double days;
// Prompting the user to enter the number of days
std::cout << "Enter number of days: ";
std::cin >> days;
if (std::cin.fail()) {
// Reject strings
std::cout << "Invalid input! Please enter a number.";
return 1;
} else if (days < 0) {
// Gracefully handle a case where the user enters a negative number of days
std::cout << "Number of days cannot be negative!";
return 1;
} else {
// Print the number of seconds in the number of days given
std::cout << "The number of seconds in " << days << " days is " << days * 24 * 60 * 60 << " seconds!" << std::endl;
return 0;
}
}