Question

In: Computer Science

Seasons Re-Visited Write a program that contains an array of strings in main(). Your array of...

Seasons Re-Visited

Write a program that contains an array of strings in main(). Your array of strings will contain the seasons, “Winter”, “Spring”, “Summer”, and “Fall”. Your program will then contain a function that will use your seasons array to display a menu and ask the user to choose their favorite season and return that value to the main() function. Your function must include a data validation loop. The user must enter in a 1 for winter, a 2 for spring, 3 for summer and 4 for fall.

Once you have returned the users numeric value back to main(), use your array and the users selection to display their favorite season.

I want the program to work but I need one or two mistake.

Solutions

Expert Solution

thanks for the question, here is a program that works but it contains two mistakes as you requested. I have commented the mistakes.

Let me know for any help or question.

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

#include<iostream>
#include<string>

using namespace std;

int getSeason(){
  
   int season ;
   cout<<"Enter 1 for Winter, 2 for Spring, 3 for Summer and 4 for Fall: ";
   cin >> season;
     
   // first mistake, we are checking the user entered a valid number
   // we simply returned the user number, user number can be 0 or 100 or 1000
   return season;
     
}

int main(){
  
   string seasons[] ={"Winter","Spring","Summer","Fall"};
   int season = getSeason();
  
   // second mistake - we must subtract 1 from the user value
   // because the index of winter is 0, spring is 1, summer is 2, and fall is 3
   cout<<"Your favourite season is: " << seasons[season];
}

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


Related Solutions

Create an array of ten strings. Write a program to join and split these strings. Feel...
Create an array of ten strings. Write a program to join and split these strings. Feel free to use any whitespace character. Explain how the program works, when to use Python arrays, and when to use tuples, dictionaries, and sets. Explain how the program works and how it can be utilized to support an organization’s requirements.
IN JAVA write a program that creates an array of strings with 8 people in it....
IN JAVA write a program that creates an array of strings with 8 people in it. Second,  Assign a random rank between 1 to 8 to each of the players. The rankings do not change throughout the tournament. Finally, Sort the players based on the rankings and print the data (show rankings of players, in square brackets, at every step after they are ranked). USING JAVA COLLECTIONS IS NOT ALLOWED
Write a program that will ask the user for three words (strings). Re-arranges them in ascending...
Write a program that will ask the user for three words (strings). Re-arranges them in ascending order by using a function (it should return void). Global variables are forbidden. Hint: You don't need to exchange the values among variables. You can just print them in the correct order. (C++ Please) Example of Output: Word 1: apple Word 2: orange Word 3: strawberry -------- orange apple strawberry
Programming lang C++ Write a program that reads 10,000 words into an array of strings. The...
Programming lang C++ Write a program that reads 10,000 words into an array of strings. The program will then read a second file that contains an undetermined number of words and search the first array for each word. The program will then report the number of words in the second list that were found on the first list.
Please in C++ language Write a program that reads 10,000 words into an array of strings....
Please in C++ language Write a program that reads 10,000 words into an array of strings. The program will then read a second file that contains an undetermined number of words and search the first array for each word. The program will then report the number of words in the second list that were found on the first list.
write a java prog that include an array of strings of size 50    String[] strings...
write a java prog that include an array of strings of size 50    String[] strings = new String[50]; then find the max length of the inputs inside a method keep reading from the user until user enters keyword to stop input : may ala jony ram asd fgghff daniel jwana output : max length : 10
Write a program that contains a main method and another method named userName. The main method...
Write a program that contains a main method and another method named userName. The main method should prompt the user to enter a full name. The userName method takes the full name as an argument and prints the name in reverse order and returns the number of characters in the name. See Sample Output (input shown in blue). Sample Output Please enter your FULL name Billy Joe McCallister Here is the name Billy Joe McCallister in reverse: retsillaCcM eoJ ylliB...
ACTIVITY #1: Defining Strings √ Write an assembly program that display your name, your id, and...
ACTIVITY #1: Defining Strings √ Write an assembly program that display your name, your id, and your college name on the screen. √ Remember: the format of the assembly program should be like this. TITLE your title (FileName.asm) .MODEL FLAT .386 .STACK 64 .DATA str1 DB "My name: Essam Alnatsheh",13,10,'$' .CODE main PROC mov ax,@data mov ds,ax mov ah,09h mov dx, offset str1 int 21h ​mov ah,4Ch​​ ; terminate process ​mov al,0​​ ; return code ​int 21h main ENDP END...
write a program using the main method where it searches through an array of positive, non-zero...
write a program using the main method where it searches through an array of positive, non-zero integer values and prints out the maximum even and odd values. The program should use the array provided in the code, and you may assume that it has already been populated with values. The results should be printed out to the console in the following format: “Max Even: ”<<max even value>> “Max Odd: ”<<max odd value>> Values denoted in “<< >>” represent variable values,...
quiz 1 write your java code Have the function SearchingChallenge(strArr) read the array of strings stored...
quiz 1 write your java code Have the function SearchingChallenge(strArr) read the array of strings stored in strArr which will be a 4x4 matrix of the characters 'C', 'H', 'F', 'O', where C represents Charlie the dog, H represents its home, F represents dog food, and O represents and empty space in the grid. Your goal is to figure out the least amount of moves required to get Charlie to grab each piece of food in the grid by moving...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT