Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include #include using namespace std; int main() { //constants declaration cons

ID: 3751988 • Letter: #

Question

#include #include using namespace std; int main() { //constants declaration const int DAYS_PER_MONTH = 30; const int const int const int MONTHS_PER_YEAR = 12; const int HOURS_IN_DAY = 24; const int MINUTES_IN_HOUR = 60; const int SECONDS_IN_MINUTES = 60; //varaible declaration string robotName = "Nao"; string visitorName; int age; int num1, num2; string programmerName = "Your Name"; int assignmentNumber = 1; string dueDate = "09/18/18"; int ageInMonths, ageInDays, ageInHours, ageInMinutes, ageInSeconds; int add; int div; float fdiv; //display programmer name and other details cout << "Programmer Name: " << programmerName << endl; cout << "Assignment Number: " << assignmentNumber << endl; cout << "Due date: " << dueDate << endl << endl; //display the script prototype cout << "Hello, welcome to Montgomery College! My name is " << robotName << ". May I have your name?" << endl; cin >> visitorName; cout << "Nice to have you with us today, " << visitorName <<"! Let me impress you with a small game. " << endl << endl << "Give me the age of an important person or a pet to you. Please give me only a number!" << endl; cin >> age; //calculate age in months, days, hours etc ageInMonths = age * MONTHS_PER_YEAR; ageInDays = ageInMonths * DAYS_PER_MONTH; ageInHours = ageInDays * HOURS_IN_DAY; ageInMinutes = ageInHours * MINUTES_IN_HOUR; ageInSeconds = ageInMinutes * SECONDS_IN_MINUTES; //display the prototype script cout << "You have entered " << age << "."; cout << "If this is for a person, the age can be expressed as " << age << " years or " << ageInMonths << " months or about " << ageInDays << " days or about " << ageInHours << " hours or about " << ageInMinutes << " minutes or about " << ageInSeconds << " seconds."; cout << "If this is for a dog, it is " << age * ONE_DOG_YEAR << " years old in human age."; cout << "If this is for a gold fish, it is " << age * ONE_GOLD_FISH_YEAR << " years old in human age."; cout << endl << endl << "Lets play another game, " << visitorName << "." << " Give me a whole number." << endl; cin >> num1; cout << "Very well. Give me another whole number." << endl; cin >> num2; add = num1+num2; div = num1/num2; fdiv = (float)num1 / (float)num2; cout << "Using the operator '+' in C++, the result of " << num1 << " + " << num2 << " is " << add << ". Using the operator '/', the result of " << num1 << " / " << num2 << " is " << div << "; however, the result of " << fixed << setprecision(1) << (float)num1 << " / " << (float)num2 << " is about " << fdiv << "."; cout << endl << "Do you like the games, " << visitorName << "? If you do, you can learn more by taking our classes. If you don't, I am sad. You should talk to our Chairman!" << endl << endl; system("pause"); return 0; } this program is not showing entirely in the control pannel

Explanation / Answer

The Program is working fine, I have adjusted the output display within the panel. Also I have handled the condition if the user enters 0 for the second whole number. Earlier if the user entered 0 the program gets crashed.

#include<iostream>
#include<iomanip>
using namespace std;
int main() { //constants declaration
const int DAYS_PER_MONTH = 30;
const int> const int> const int MONTHS_PER_YEAR = 12;
const int HOURS_IN_DAY = 24;
const int MINUTES_IN_HOUR = 60;
const int SECONDS_IN_MINUTES = 60; //varaible declaration
string robotName = "Nao";
string visitorName;
int age;
int num1, num2;
string programmerName = "Your Name";
int assignmentNumber = 1;
string dueDate = "09/18/18";
int ageInMonths, ageInDays, ageInHours, ageInMinutes, ageInSeconds;
int add;
int div;
float fdiv; //display programmer name and other details
cout << "Programmer Name: " << programmerName << endl;
cout << "Assignment Number: " << assignmentNumber << endl;
cout << "Due date: " << dueDate << endl << endl; //display the script prototype
cout << "Hello, welcome to Montgomery College! My name is " << robotName << ". May I have your name?" << endl;
cin >> visitorName;
cout << "Nice to have you with us today, " << visitorName <<"! Let me impress you with a small game. " << endl << endl;
cout<< "Give me the age of an important person or a pet to you. Please give me only a number!" << endl;
cin >> age; //calculate age in months, days, hours etc
ageInMonths = age * MONTHS_PER_YEAR;
ageInDays = ageInMonths * DAYS_PER_MONTH;
ageInHours = ageInDays * HOURS_IN_DAY;
ageInMinutes = ageInHours * MINUTES_IN_HOUR;
ageInSeconds = ageInMinutes * SECONDS_IN_MINUTES; //display the prototype script
cout << "You have entered " << age << "."<<endl;
cout << "If this is for a person, the age can be expressed as " <<endl<< age;
cout<< " years or " <<endl<< ageInMonths << " months or about " <<endl<< ageInDays << " days or about "<<endl;
cout<< ageInHours << " hours or about " <<endl<< ageInMinutes << " minutes or about "<<endl << ageInSeconds << " seconds."<<endl<<endl;
cout << "If this is for a dog, it is " << age * ONE_DOG_YEAR << " years old in human age."<<endl<<endl;
cout << "If this is for a gold fish, it is " << age * ONE_GOLD_FISH_YEAR << " years old in human age.";
cout << endl << endl << "Lets play another game, " << visitorName << "." << " Give me a whole number." << endl;
cin >> num1;
cout << "Very well. Give me another whole number." << endl;
cin >> num2;
while(1)
{
if(num2==0)
{
cout << "Please enter any number other than 0." << endl;
cin>>num2;
}
else
break;
}
add = num1+num2; div = num1/num2;
fdiv = (float)num1 / (float)num2;
cout << "Using the operator '+' in C++, the result of " << num1 << " + " << num2 << " is " << add;
cout<< ". Using the operator '/', the result of " << num1 << " / " << num2 << " is " << div ;
cout<< "; however, the result of " << fixed << setprecision(1) << (float)num1 << " / " << (float)num2 << " is about " << fdiv << ".";
cout << endl << "Do you like the games, " << visitorName;
cout<< "? If you do, you can learn more by taking our classes. If you don't, I am sad. You should talk to our Chairman!" << endl << endl;
system("pause");
return 0;
}