Question

In: Computer Science

(c++) error: =================== MISMATCH FOUND ON LINE 0002: ===================                             

(c++) error:

=================== MISMATCH FOUND ON LINE 0002: ===================                                         

ACTUAL  : 0~years                                                                                            

EXPECTED: may~3                                                                                              

======================================================

#include <iostream>
#include <string>
using namespace std;

int main()
{
const int DAYS[]= { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
const string MONTHS[]= {"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};
  
int day, month;
int totalYears=0;
  
while(true)
{
cout<< "Please enter a day of the year (0 to exit): ";
cin>>day;
cout<<day<<endl;
  
if(day == 0)
{
break;
}
else if (day<0)
{
cout<<"Invalid Input!";
}
else
{
  
if(day>365)
totalYears=day/365;
  
if(totalYears == 1)
{
cout<<totalYears<<" year";
cout<<endl;
}
else
{
cout<<totalYears<<" years";
cout<<endl;
}
  
}
  
day=day- (totalYears * 365);
  
for(int i=0; i<12; i++)
{
if(DAYS[i]>day-1)
{
cout<<MONTHS[i]<<" ";
if(day>31)
{
cout<<day - DAYS[i-1]<<endl;
}
else
{
cout<<day<<endl;
}
break;
}
}
}
  
cout<<"Thanks for playing!"<<endl;
  
return 0;
}

INSTRUCTIONS:

Given a number, calculate how many years into the future it is, and what date. Assume no leap years. For example: Please enter a day of the year (0 to exit): 1 jan 1 Please enter a day of the year (0 to exit): 365 dec 31 Please enter a day of the year (0 to exit): 366 1 year jan 1 Please enter a day of the year (0 to exit): 0 Thanks for playing!

Solutions

Expert Solution

Hi Student,

There is a minor mistake in the if else loop. You just need to change the below lines

else
{
  
if(day>365)

to

else if(day> 365) {

Complete code is given below for your referance

#include <iostream>
#include <string>
using namespace std;


int
main ()
{
  
const int DAYS[] =
{ 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
  
const string MONTHS[] =
{ "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct",
"nov", "dec" };
  

int day, month;
  
int totalYears = 0;
  

while (true)
  
{
  
cout << "Please enter a day of the year (0 to exit): ";
  
cin >> day;
  
cout << day << endl;
  

if (day == 0)
  
   {
  
break;
  
}
  
else if (day < 0)
  
   {
  
cout << "Invalid Input!";
  
}
  
else if (day > 365)
  
   {
  

totalYears = day / 365;
  

if (totalYears == 1)
  
   {
  
cout << totalYears << " year";
  
cout << endl;
  
}
  
   else
  
   {
  
cout << totalYears << " years";
  
cout << endl;
  
}
  

}
  


day = day - (totalYears * 365);
  

for (int i = 0; i < 12; i++)
  
   {
  
if (DAYS[i] > day - 1)
  
   {
  
cout << MONTHS[i] << " ";
  
if (day > 31)
      
       {
      
cout << day - DAYS[i - 1] << endl;
      
}
  
   else
      
       {
      
cout << day << endl;
      
}
  
break;
  
}
  
}
  
}
  

cout << "Thanks for playing!" << endl;
  

return 0;

}

I had checked the working of the program thoroughly.


Related Solutions

(c++) error: =================== MISMATCH FOUND ON LINE 0007: ===================                             
(c++) error: =================== MISMATCH FOUND ON LINE 0007: ===================                                          ACTUAL  : 2~year                                                                                              EXPECTED: 2~years                                                                                             ====================================================== #include <iostream> using namespace std; int main() { const int MonthDays[]= { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 ,31 }; const string MonthName[]= {"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};    int day; int year=0; int index;    while(1) { cout<<"Please enter a day of the year (0 to exit): "; cin>>day; cout<<day<<endl;    if(day==0) { break; }    index=0; year=0; while(day>365) { day=day-365; year++; }   ...
1- The margin of error used in a confidence interval is found by ________. A- multiplying...
1- The margin of error used in a confidence interval is found by ________. A- multiplying the standard error and z?/. 2B- multiplying the population standard deviation and the sample size. C- dividing the population standard deviation by the sample size. D- multiplying the level of confidence and the standard error. Which one is correct 2- To determine whether a linear relationship exists between variables, a ________ can be used. bar chart pie chart scatter chart stacked column chart 3-...
Molex Inc. and their reporting of a financial error found during their audit. This is the...
Molex Inc. and their reporting of a financial error found during their audit. This is the only company on the S&P 500 Index to have reported an error during the year. Do you think it is because companies are doing a better job reporting on their financial statements or do you think it is just because they are getting away with the fraud? What techniques have you learned so far in class that you could have implemented to help catch...
QUESTION 17 If a sample average is found to be 62.7, and the margin of error...
QUESTION 17 If a sample average is found to be 62.7, and the margin of error is calculated to be 4.6, then the upper end of the confidence interval for mu would be ______ QUESTION 18 If a sample average is found to be 18, and the margin of error is calculated to be 0.06, then the lower end of the confidence interval for mu would be ______ QUESTION 19 Use your TI83 to find the upper end of the...
Describe the mechanism underlying the below repair mechanisms. a. Mismatch Repair b. Postreplication Repair c. SOS...
Describe the mechanism underlying the below repair mechanisms. a. Mismatch Repair b. Postreplication Repair c. SOS Repair d. Photoreactivation Repair e. Base Excision Repair f. Nucleotide Excision Repair g. Doublestranded Break Repair
Why am I getting error below? sh-3.2# ./week4prog1[name].scr ./week4prog1[name].scr: line 2: count: command not found start...
Why am I getting error below? sh-3.2# ./week4prog1[name].scr ./week4prog1[name].scr: line 2: count: command not found start of the program ./week4prog1[name].scr: line 4: [: -le: unary operator expected end of the program Below is my vim script I am running. I can't see the error, please help: #!/bin/bash count =1 echo "start of the program" while [ $count -le 10 ] do echo "Loop #$count" sleep 10 count=$[ count + 1] done echo "end of the program"
Find the margin of error for the given values of c, σ, and n. c =...
Find the margin of error for the given values of c, σ, and n. c = 0.98, σ = 0.78, n = 150
(a) Find the margin of error for the given values of​ c, σ​, and n. c...
(a) Find the margin of error for the given values of​ c, σ​, and n. c = 0.90​, σ = 3.8​, n = 100 E= _ (Round to three decimal places as​ needed.) (b) Construct the confidence interval for the population mean μ. c = 0.90 ​, x=9.1​, σ = 0.3 ​, and n = 47 A 90​% confidence interval for μ is _, _ (Round to two decimal places as​ needed.) (c)  Construct the confidence interval for the population mean...
Error detection/correction C Objective: To check a Hamming code for a single-bit error, and to report...
Error detection/correction C Objective: To check a Hamming code for a single-bit error, and to report and correct the error(if any) Inputs: 1.The maximum length of a Hamming code 2.The parity of the check bits (even=0, odd=1) 3.The Hamming code as a binary string of 0’s and 1’s Outputs: 1.The original parity bits (highest index to lowest index, left to right) 2.The new parity bits (highest index to lowest index, left to right) 3.The bit-wise difference between the original parity...
I am having an error in this function. It says Max was not found. int height()...
I am having an error in this function. It says Max was not found. int height() const {    if (is_null()) return 0; return 1 + max(get_left_subtree().height(), get_right_subtree().height()); } The whole code is #ifndef BINARY_TREE_H #define BINARY_TREE_H #include <cstddef> #include <sstream> #include <stdexcept> #include <string> #include <algorithm> #include "BTNode.h" template<typename Item_Type> class Binary_Tree { public: Binary_Tree() : root(NULL) {} Binary_Tree(const Item_Type& the_data, const Binary_Tree<Item_Type>& left_child = Binary_Tree(), const Binary_Tree<Item_Type>& right_child = Binary_Tree()) : root(new BTNode<Item_Type>(the_data, left_child.root, right_child.root)) {} virtual ~Binary_Tree()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT