can\'t quite get it to work, it would be helpful if you posted yourcode so i cou
ID: 3609517 • Letter: C
Question
can't quite get it to work, it would be helpful if you posted yourcode so i could compare. Thanks#include <iostream>
#include <cstdlib>
using namespace std;
/*
* Prototypes for the functions
*/
bool find(int n, int list[], int target);
char yesNo();
/**
* This program will read a sequence of integer numbers andlook for
* a specific number in the set. (Maximum 20 numbers in theset!)
*/
int main()
{
// Variables declaration
const int SIZE = 20;
int list[SIZE], listsize, searchnum, num;
char userchar;
cout << "An Integer List and SearchProgram" << endl <<endl;
// Get a sequence of integer numbers
cout << "How many numbers there are in theset? ";
cin >> listsize;
cout << "Enter the numbers: ";
cin >> num;
cout << endl <<endl<<endl;
//Search for a number until the user wants tostop
do {
cout << "What numberwould you like to search for? " <<endl;
cin >> searchnum;
find(num, list[],searchnum);
if (searchnum != num){
cout << "The number " <<searchnum << " is not inthe list." <<endl;}
else {
cout << "The number " << searchnum << " is in thelist." <<endl;}
userchar=yesNo();
} while (userchar=='Y' ||userchar=='y');
cout << endl;
cout << " End of the program...";
system("PAUSE");
}
bool find(int n, int list[], int target)
{
int index=0;
for (int i=1; i<n; i++){
if (list[i] >list[index]){
index = i;
return true;}
else{
return false;}}
}
char yesNo(){
char result;
bool valid=false;
while (valid==false){
cout<<"Do you want tosearch again? (Y/y or N/n) ";
cin>>result;
//check to see if it isvalid..
if ((result=='y') ||(result=='Y') || (result=='n') || (result=='N'))
valid=true;
else
cout<<"You have to type a valid character.... Tryagain"<<endl;
}//end while
//sends the valid character back
return result;
}
Explanation / Answer
can't quite get it to work, it would be helpful if you posted yourcode so i cou
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.