C++ Help Simple Mistake

This is the program below, program runs great, only thing I am confused about is fixing: if(raffle(number)==false) so it can say on the file "The number "XX" is not present in the array" Also if you see any mistakes please point them out so I can learn to be a better programmer. Thanks.

#include <iostream>
#include <iomanip>
#include <ctime>
#include <fstream>


void ascii (int number);
bool raffle (int number);

using namespace std;

int main()
{


int number;
char select;


ofstream output("c:/Text6.txt", ios::out);


cout<<endl;
cout<<"Please enter a positive integer number: ";
cin>>number;
cout<<endl;


cout<<"A[scii]\t\tR[affle]\t\tE[xit]";
cout<<endl;
cout<<"Please select an option:";
cin>>select;
cout<<endl;

switch (select)

{
case 'a':
case 'A':
ascii(number);
break;

case 'r':
case 'R':

if(raffle(number)==true);
output<<"The number "<<number<<" is present in the array";
output.close();
break;




if(raffle(number)==false);
output<<"The number "<<number<<" is not present in the array";
output.close();
break;



case 'e':
case 'E':
return 0;

}

}


void ascii (int number)

{
if(number>47 && number<58)
cout<<"The number corresponds to a digit"<<endl<<endl;
else
if(number>64 && number<90)
cout<<"The number corresponds to a uppercase letter"<<endl<<endl;
else
if(number>96 && number<123)
cout<<"The number corresponds to a lowercase letter"<<endl<<endl;
else
cout<<"The number does not correspond to uppercase letter, lowercase letter, or digit"<<endl<<endl;

}



bool raffle(int number)

{

int array[6];
int count=0;
srand(time(NULL));

for(int i=0; i<5; i++)
{
array[i]=rand() % 101;
cout<<setw(8)<<array[i];
}

cout<<endl;


for(int i=0; i<5; i++)
{
if(number==array[i])
{
cout<<endl;
cout<<"The number can be found in position "<<i+1<<" of the array"<<endl<<endl;
return true;
}
}


for(int i=0; i<5; i++)
{
if(number!=array[i])
{
cout<<endl;
cout<<"The number was not found in the array"<<endl<<endl;
return false;
}
}

}
1) Please put your code around code blocks which are generated with the <> button
2) Im pretty sure that:
1
2
3
4
case 'a':
case 'A':
//code here
break;

is invalid but not:
1
2
3
4
5
6
7
case 'a':
//code here
break;

case 'A':
//code here
break;

start off with that
@ConfusedLearner

You need an else:
1
2
3
4
5
6
if(raffle(number)) // Unnecessary: ==true);<- Note that a semicolon directly after if is wrong
output<<"The number "<<number<<" is present in the array";
else
output<<"The number "<<number<<" is not present in the array";
output.close();
break;


@Aramil of Elixia
2) is perfectly valid
@Aramil: that's a common construct for case sensitivity. If the result for 'a' and 'A' is the same, you can group labels like that.
oh ok I did not know that. I figured it wouldn't be because c++ is case sensitive for the most part
Thank the program works great, but why does my A[scii] not working as I enter "a" im confused about it.
Topic archived. No new replies allowed.