Question

In: Computer Science

(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++;
}
  
if(year !=0)
{
cout<<year<<" year"<<endl;
}
  
index=0;
while(day>MonthDays[index])
{
day=day-MonthDays[index];
index++;
}
cout<<MonthName[index]<<" "<<day<<endl;
}
  
cout<<"Thanks for playing!";
  
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

I have answered this before. Your test program is expecting an output of ‘2 years’ for some input, but your program is giving ‘2 year’ (no s at the end). So I fixed your code to print years instead of year if n is not 1. Also your code had some misplaced statements. I made some rearrangements, now it runs perfectly as needed.

NOTE: Copy the entire code from below, and try running. DO NOT JUST CHANGE YEAR TO YEARS OR VICE VERSA. IT WONT WORK. Modified code is highlighted in bold text. Thanks

#include <iostream>

using namespace std;

int main()

{

    int daynum, n;

    cout << "Please enter a day of the year (0 to exit): ";

    cin >> daynum;

    while (daynum > 0) {

                //checking if daynum>365 at the beginning of loop

                if (daynum > 365) {

            n = daynum / 365;

            if(n==1){

                //printing year instead of years for n=1

                cout << n << " year" << endl;

                                               }else{

                                                               //printing years instead of year for n>1

                                                               cout << n << " years" << endl;

                                               }

            //updating daynum, so that it will be under 365

            daynum = daynum - (365 * n);

        }

        //now finding the day of year

        if (daynum >= 1 && daynum <= 31)

            cout << "jan " << daynum << endl;

        else if (daynum > 31 && daynum <= 59) {

            cout << "feb " << daynum - 31 << endl;

        }

        else if (daynum > 59 && daynum <= 90) {

            cout << "mar " << daynum - 59 << endl;

        }

        else if (daynum > 90 && daynum <= 120) {

            cout << "apr " << daynum - 90 << endl;

        }

        else if (daynum > 120 && daynum <= 151) {

            cout << "may " << daynum - 120 << endl;

        }

        else if (daynum > 151 && daynum <= 181) {

            cout << "jun " << daynum - 151 << endl;

        }

        else if (daynum > 181 && daynum <= 212) {

            cout << "jul " << daynum - 181 << endl;

        }

        else if (daynum > 212 && daynum <= 243) {

            cout << "aug " << daynum - 212 << endl;

        }

        else if (daynum > 243 && daynum <= 273) {

            cout << "sep " << daynum - 243 << endl;

        }

        else if (daynum > 273 && daynum <= 304) {

            cout << "oct " << daynum - 273 << endl;

        }

        else if (daynum > 304 && daynum <= 334) {

            cout << "nov " << daynum - 304 << endl;

        }

        else if (daynum > 334 && daynum <= 365) {

            cout << "dec " << daynum - 334 << endl;

        }

        cout << "Please enter a day of the year (0 to exit): ";

        cin >> daynum;

    }

    if (daynum == 0)

        cout << "Thanks for playing!";

    if (daynum < 0)

        cout << "Invalid input!";

    return 0;

}

//OUTPUT

Please enter a day of the year (0 to exit): 1

jan 1

Please enter a day of the year (0 to exit): 2

jan 2

Please enter a day of the year (0 to exit): 300

oct 27

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): 789

2 years

feb 28

Please enter a day of the year (0 to exit): 10000

27 years

may 25

Please enter a day of the year (0 to exit): 0

Thanks for playing!


Related Solutions

(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...
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...
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...
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"
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...
1. Find the margin of error for the given values of​ c, sigma​, and c= 0.90​,...
1. Find the margin of error for the given values of​ c, sigma​, and c= 0.90​, sigma =2.3​, n= 49 2. Use the confidence interval to find the margin of error and the sample mean. (0.512,0.690) 3. Find the minimum sample size n needed to estimate μ for the given values of​ c, σ​, and E. c=0.98​, σ=5.8​, and E =2 Assume that a preliminary sample has at least 30 members.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT