Question

In: Computer Science

** IN C++ ** Ex: If the input is: April 11 the output is: Spring In...

** IN C++ **

Ex: If the input is:

April 11

the output is:

Spring

In addition, check if the string and int are valid (an actual month and day).

Ex: If the input is:

Blue 65

the output is:

Invalid 

The dates for each season are:
Spring: March 20 - June 20
Summer: June 21 - September 21
Autumn: September 22 - December 20
Winter: December 21 - March 19

My code isn't working and I can't figure out why please help.

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

int main() {
string inputMonth;
int inputDay;

cin >> inputMonth;
cin >> inputDay;

if (inputMonth = "March") && (inputDay > 19) && (inputDay < 32) {
cout << "Spring" << endl;
}

else if (inputMonth = "April" && inputDay > 0 && inputDay < 31) {
cout << "Spring" << endl;
}

else if (inputMonth = "May" && inputDay > 0 && inputDay < 32) {
cout << "Spring" << endl;
}

else if (inputMonth = "June" && inputDay > 0 && inputDay < 21) {
cout << "Spring" << endl;
}

else if (inputMonth = "June" && inputDay > 20 && inputDay < 31) {
cout << "Summer" << endl;
}

else if (inputMonth = "July" && inputDay > 0 && inputDay < 32) {
cout << "Summer" << endl;
}

else if (inputMonth = "August" && inputDay > 0 && inputDay < 32) {
cout << "Summer" << endl;
}

else if (inputMonth = "September" && inputDay > 0 && inputDay < 23) {
cout << "Summer" << endl;
}

else if (inputMonth = "September" && inputDay > 24 && inputDay < 31) {
cout << "Autumn" << endl;
}

else if (inputMonth = "October" && inputDay > 0 && inputDay < 32) {
cout << "Autumn" << endl;
}

else if (inputMonth = "November" && inputDay > 0 && inputDay < 31) {
cout << "Autumn" << endl;
}

else if (inputMonth = "December" && inputDay > 0 && inputDay < 22) {
cout << "Autumn" << endl;
}

else if (inputMonth = "December" && inputDay > 23 && inputDay < 32) {
cout << "Winter" << endl;
}

else if (inputMonth = "January" && inputDay > 0 && inputDay < 32) {
cout << "Winter" << endl;
}

else if (inputMonth = "February" && inputDay > 0 && inputDay < 29) {
cout << "Winter" << endl;
}

else if (inputMonth = "March" && inputDay > 0 && inputDay < 20) {
cout << "Winter" << endl;
}

else {
cout << "Invalid" << endl;
}

return 0;
}

Solutions

Expert Solution

Answer-

Your code is given below-

  • #include <iostream>
  • #include <string>
  • using namespace std;
  • int main() {
  • string inputMonth;
  • int inputDay;
  • cin >> inputMonth >> inputDay;
  • if ((inputMonth == "January" && inputDay >= 1 && inputDay <= 31) || (inputMonth == "February" && inputDay >= 1 && inputDay <= 29) || (inputMonth == "March" && inputDay >= 1 && inputDay <= 19) || (inputMonth == "December" && inputDay >= 21 && inputDay <= 30))
  • cout << "Winter" << endl;
  • else if ((inputMonth == "April" && inputDay >= 1 && inputDay <= 30) || (inputMonth == "May" && inputDay >= 1 && inputDay <= 30) || (inputMonth == "March" && inputDay >= 20 && inputDay <= 31) || (inputMonth == "June" && inputDay >= 1 && inputDay <= 20))
  • cout << "Spring" << endl;
  • else if ((inputMonth == "July" && inputDay >= 1 && inputDay <= 31) || (inputMonth == "August" && inputDay >= 1 && inputDay <= 31) || (inputMonth == "June" && inputDay >= 21 && inputDay <= 30) || (inputMonth == "September" && inputDay >= 1 && inputDay <= 21))
  • cout << "Summer" << endl;
  • else if ((inputMonth == "October" && inputDay >= 1 && inputDay <= 31) || (inputMonth == "November" && inputDay >= 1 && inputDay <= 30) || (inputMonth == "September" && inputDay >= 22 && inputDay <= 30) || (inputMonth == "December" && inputDay >= 0 && inputDay <= 20))
  • cout << "Autumn" << endl;
  • else
  • cout << "Invalid" << endl;
  • return 0;
  • }

Screenshot of some sample output-

Note- Please do upvote, if any problem then comment in box sure I will help.


Related Solutions

Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
Define a problem with user input, user output, -> operator and destructors. C ++ please
Define a problem with user input, user output, -> operator and destructors. C ++ please
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string...
A C program that will perform the following: Input the string: Abc_3_deF Expected Output: The string you entered is: aBC_Three_DEf An output for just this specific input will be fine. If you want to provide a program for all outputs, it would help with my understanding of how the program works overall as well but it is not needed. Thanks!
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
C Programming: Write a program that accepts 2 arguments, an input file and an output file....
C Programming: Write a program that accepts 2 arguments, an input file and an output file. The program is to store in the output file the contents of the input file in reverse. If the input file looks like this: Hello World.\n This is Line 2\n This is the end.\n then the output file should look like this: \n .dne eht si sihT\n 2 eniL si sihT\n .dlroW olleH The main program should look like this: int main(int argc, char...
Write a C program whose input is two integers, and whose output is the first integer...
Write a C program whose input is two integers, and whose output is the first integer and subsequent increments of 10 as long as the value is less than or equal to the second integer. Ex: If the input is: -15 30 the output is: -15 -5 5 15 25 Ex: If the second integer is less than the first as in: 20 5 the output is: Second integer can't be less than the first. For coding simplicity, output a...
The input-output (consumption) matrix for a closed economy is given below. Solve the associated input- output...
The input-output (consumption) matrix for a closed economy is given below. Solve the associated input- output model. Use r if you need a variable in your answer. [0.07 0.05 0.27] [0.17 0.48 0.19] [0.76 0.47 0.54]
11. Using the notions of ex ante and ex post interest rates, explain how a bank...
11. Using the notions of ex ante and ex post interest rates, explain how a bank could be expecting a huge return on its investments and end up with very small real returns.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT