Programming in c++(visual studio 2019):
I’m prompting the user to input “even odd or random” to start my code and noticed the while loop I use to check of the user input is valid or not freaks out if I go over the char limit I gave the user input. Can I fix this or do I just need to increase the input size?
Process by which instructions are given to a computer, software program, or application using code.
Expert Solution
Introduction:
C++ is a programming language. It is simple and easy to use because programs are concerned with simple task like calculations.
The most widely used concept in C++ is OOPS concept. (Object Oriented Programming Language).
Given Program
#include <iostream> #include <fstream> #include <cstring> using std::ofstream; using std::end1; using std::count; using std::cin; int getinput(int& userInput); int main() { int userInput; const int MAX = 500; int array[MAX]; getinput(userInput); cout << userInput << end1; while (userInput !=1 && userInput !=2 && userInput != 3) { if (userInput == 0) { cout << "Not a valid input. Try again:" << end1; getinput(userInput); } } int getinput(int& userInput) { char user[8]; cout << "Is your array Even, Odd or Random?" << end1; std::cin.getline(user, sizeof user); if (_stricmp(user, "odd") == 0) { userInput = 1; return userInput; } else if (_stricmp(user, "Even") == 0) { userInput = 2; return userInput; } else if (_stricmp(user, "Random") == 0) { userInput = 3; return userInput; } else { userInput = 0; return userInput; } } }
In the given program the following errors:
Step by step
Solved in 4 steps with 5 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.