Concept explainers
(Assume the user enters 36720152. Use a calculator.)
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
long seconds;
double minutes, hours, days, months, years;
cout << "Enter the number of seconds that have\n”;
cout << "elapsed since some time in the past and\n
cout << "I will tell you how many minutes, hours,\n
cout << "days, months, and years have passed: ";
cin >> seconds;
minutes = seconds / 60;
hours = minutes / 60;
days = hours / 24;
years = days / 365;
months = years * 12;
cout << setprecision(4) << fixed << showpoint << right;
cout << "Minutes: " << setw(6) << minutes << endl;
cout << "Hours: " << setw(6) << hours << endl;
cout << "Days: " << setw(6) << days << endl;
cout << "Months: " << setw(6) << months << endl;
cout << "Years: " << setw(6) << years << endl;
return 0;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Additional Engineering Textbook Solutions
Artificial Intelligence: A Modern Approach
Modern Database Management (12th Edition)
C How to Program (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Digital Fundamentals (11th Edition)
Starting Out With Visual Basic (8th Edition)
- 30 Suppose a, b, and sum are int variables and c is a double variable. What value is assigned to each variable after each statement executes? Suppose a = 6, b = 3, and c = 2.2. (14) a b c sum sum = static_cast<int>(a + b + c); __ __ __ __ b += c * a; __ __ __ __ c -= a; __ __ __ __ a *= 2 * b - c; __ __ __ __arrow_forwardAnswer the given question with a proper explanation and step-by-step solution. 13.Complete the following code: #include <iostream>using namespace std;int main(){int a = 10;int b = 20;// Write code here to swap the values currently assigned to variables a and b. cout << “The values of a and b have been swapped.” << endl;}arrow_forwardint main() { E(); C(); E(); } void B() {...} void C() {..} void D() {..} void E() { B(); D(); } A variable declared in function B and only in function B is accessible in?arrow_forward
- Q3: Write a program in which user is asked to enter two integers (divisor and dividend) and computes the quotient and remainder. To compute quotient and remainder, both divisor and dividend should be integers.arrow_forwardComputer Fundamentals and Programming 2 Write a program that determines a student’s grade. The program will accept 3 scores and computes the average score. Determine the grade based on the following rules: - If the average score is equal or greater than 90, the grade is A. - If the average score is greater than or equal to 70 and less than 90, the grade is B. - If the average score is greater than or equal to 50 and less than 70, the grade is C. - If the average score is less than 50, the grade is F. Source Codes and Print Screen of the Outputarrow_forwardAssume variables a, b, c, are declared int and are initialized. Write code that will find the largest value of a, b, and c, and store the largest value to int variable smallest. (code in C)arrow_forward
- 8. Write a program that allows the user to enter two integers and a character If the character is A, add the two integers If it is S, subtract the second integer from the first if it is M, multiply the integers Display the results of the arithmetic The following problems requires nested if-statements9. Write a console-based application that asks a user to enter an IQ score. If the score is a number less than 0 or greater than 200, issue an error message; otherwise, issue an “above average”, “average”, or “below average” message for scores over, at, or under 100, respectively.10. Write a console-based program that prompts a user for an hourly pay rate. If the user enters values less than $7.50 or greater than $49.99, prompt the user again. If the user enters an invalid value again, display an appropriate error message. If the user enters a valid value on either the first or second attempt, display the pay rate as well as the weekly rate, which is calculated as 40 times the hourly rate.…arrow_forwardExamine the following code segment. What will be printed? If there are any errors indicate the nature of the error. int a[9] = { 1, 12, 3, 14, 25, 16, 7, 8, 9 }; int *ptr ; ptr = & a[ 2 ] ; for( i = 1; i <= 5; i = i + 2) cout << a[i] << *( ptr + i ); cout << ” ” << a[0] << ” ” << *ptr << ” ” << *ptr - 1 << ” ” << *(ptr - 2));arrow_forwardWhat is the output of the code below? def mystery_func(input, num, t = 0, x = 10, y = 10)[this function multiples all arguments together (except t) and raises the result to the power of t and returns this]print(mystery_func(2, 3))arrow_forward
- int the given statement 10 timarrow_forwardWhy won't this code run in C++? #include<iostream>#include<stdlib>void main(){int A,B,i,sum=0;cout<<endl<<"Enter any two even numbers: ";cin>>A>>B;if(A%2==1||B%2==1) // checking whether given numbers are even or not{cout<<"Invalid input: Enter only even numbers"<<endl;exit(1);}else if(A>B) // checking whether A is greater than B or not{cout<<"Invalid input: First number A must be smaller than Second number B"<<endl;exit(1);}else{for(i=A;i<=B;i++){if(i%2==0) // checking for even number{sum=sum+(i*i);}}}cout<<"Sum of even numbers between "<<A<<" and "<<B<<" is "<<sum<<endl;}arrow_forward#include <iostream> using namespace std; char let; int Final (int &num1, int num2); double Final (double num1, double &num2); int main( ) { int a, b, c; double line[5] = {1, 2, 3, 4, 5}; a = 200; b = 100; c = 10; let = 'A'; c = Final (a, b); line[0] = Final (line[2], line[2]); for (int i = 0; i < 5; i++) cout << line[i] << endl ; cout << let << endl; return 0; } int Final (int &num1, int num2) { int sum, num3 = 10; let = 'X'; num2 = num3; sum = num1 + num2; return sum; } double Final (double num1, double &num2) { double sum, num3 = 3.1; num2 = num3; sum = num1 + num2; return sum;arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,