mrnutty 761 Senior Poster

What is the first term in the Fibonacci sequence to contain 1000 digits?

so i made a program that finds the fibonocci's sequence (fs).
I tried to do it recursively but it takes too long for big numbers. so i made a manual one.

BUt as i count how many digits there are for each (fs). a problem exist. After F(1476)--which has 309 digits, the program stops suddenly. I think its because of memory space or something. Any ways, this is why I turned to you. any help

here is my code

#include<iostream>
#include<fstream>
#include<iomanip>
#include<cmath>
using namespace std;

int countdigits(unsigned long double x)
{	
	int count(0);

	while(x>.99999999999999)
	{
		
		x/=10;
		count++;
	}
	return count;
}



int main(){

unsigned long double result = 0.0;
unsigned long double x = 1.0;
unsigned long double y = 1.0;
unsigned long double result2 = 0.0;
int count(0);
for(int i = 3;;i++)
{
	result = x+y;
	y = x;
	x = result;
	result2 = result;
	cout<<setprecision(10)<<"F of "<<i<<" is : "<<result/1000000<<"	count is : "<<countdigits(result2)<<endl;

	if(( countdigits(result2) == 1000 ) )
	{
		
		cin.get();
	}


}

return 0;
}

try running the program to get a better understanding , and then maybe you can help be better. thanks :)

mrnutty 761 Senior Poster

I got it by the brutal force method.
I'm too lazy to install gdb library (probably the simplest solution).
The code below is not carefully tested, I did it for fan, no warranties ;):

class Num {
public:
    struct err { 
        const char* what() const {
            return "Num::err raised";
        }
    };
    Num(const char* pnum = 0);
    Num(const std::string& num);
    Num(unsigned long n);

    std::string toString() const;
    operator const std::string() const {
        return toString();
    }
    Num operator+(const Num& num) const;
    Num operator*(const Num& num) const;
    unsigned long s10() const;
    Num test(unsigned d) { return mult(d); }
private:
    void m10(unsigned n);
    Num mult(unsigned d) const;
    std::string s;
};

inline
std::ostream& operator <<(std::ostream& os, const Num& num)
{
    os << num.toString();
    return os;
}

const char* digits = "0123456789";
const std::string sdigits(digits);

Num Num::operator+(const Num& num) const
{
    std::string res;
    size_t len1 = s.size();
    size_t len2 = num.s.size();
    unsigned p, q, x, y = 0;
    size_t n = (len1 < len2? len2: len1);

    for (size_t i = 0; i < n; ++i) {
        p = (i < len1? s[i]: 0);
        q = (i < len2? num.s[i]: 0);
        x = p + q + y;
        if (x >= 10) {
            x -= 10;
            y = 1;
        } else
            y = 0;
        res += char(x);
    }
    if (y)
        res += '\1';
    Num sum;
    sum.s = res;
    return sum;
}


std::string Num::toString() const
{
    std::string res;
    if (s.size()) {
        size_t n = s.size() - 1;
        for (int i = n; i >= 0; --i)
            res …
mrnutty 761 Senior Poster

your problem is your cout statement.

instead of cout<<mat[l];

it should be cout<<mat[l][k];

mrnutty 761 Senior Poster

s10(2^1000) == 1366
2^1000 == 1071508607186267320948425049060001810561404811705533607443750388370351
05112493612249319837881569585812759467291755314682518714528569231404359845775746
98574803934567774824230985421074605062371141877954182153046474983581941267398767
559165543946077062914571196477686542167660429831652624386837205668069376
;)

could you hint on how you got 2^1000?

mrnutty 761 Senior Poster

do you want all the numbers together? or only 1 at a time and get it into an array...
Here's what i did
get it as a string

char line[2500];
ifstream num("num.txt");
num.getline(line,2500); // get the line
num.close();
int array[2500];
for(int i = 0; i < (int)strlen(line); i++)
    array[i] = (int)line[i]-48; // -48 because '0' = 48, '1' = 49, it gives normal int...

I get it, but it seems that your code gets only a line. Where as I need about a hundred of line worth of numbers. Ant clue on how to tell the compiler that if it reaches a number < 0 , then skip it go to new line?

mrnutty 761 Senior Poster

how would I check how long a program takes for it to be completed.
(i.e the time it takes for the program to be finished doing its calculation)) Thanks

mrnutty 761 Senior Poster

hi,
I am curious, how can I read a int from a text file( ex. num.txt).
but this text file contains numbers without spacing
(ex.1212132132313...
23156897984969..
583852935792...)

The problem is that this file has no spaces between numbers and when i try to read it into an arry, the result is zero because it cant hold such huge --over 1000 integer.

here is my code :

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

int main(){

	ifstream num("num.txt");
	
	__int64 arry[25000]={0};

	for(int i=0; (i<2500 && (!num.eof())) ; i++)
	{
		num >> arry[i];

	
	}


		return 0;
}
mrnutty 761 Senior Poster

cout<<fixed << setprecision(50)<<"i is : "<<i< ...

Don't be supprised when it displays this:

I see but this is not precise. The output screen displays

9.33......000;

but i am confused because, I know really that 100! has a lot more significant digits and not all that zeros. I think when I declared
unsigned long double fact. The computer could not hold all the real values of 100! so it probably truncacated untill what it could hold and thus set the rest to zero.

My question is that how can I get all the number of 100! ( ex. when i use my computer to calculate 100! it gives me 9.332621544....267e+157) because of this i know there are more number to 100! than what my programs gives me. So any hints or help on how i could get
my program from outputing this: 93326215443944090000000000000000000000000000...
into something loke 9.332621544394409....12457.000 ? ??

mrnutty 761 Senior Poster

I made a program that computes a factorial of a number.

#include<iostream>
#include<fstream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
//unsigned __int64 Fact(unsigned __int64 x );


int main(){


unsigned __int64 num = 100;
unsigned long double fact(1);

for(unsigned __int64 i=1;i<=num;i++)
{
	fact *=i;
	cout<<setprecision(50)<<"i is : "<<i<<"	fact is : "<<fact<<endl;
	
}

return 0 ;
}

The problem is I can't convert 100! into all of its significants digits. The output is 9.3326215443944102 e+157;
How could I get all the number to show. "setprecision" dosen't work here.

any help ???

mrnutty 761 Senior Poster

checked again anything over 20! is not correct. anyhelp?

mrnutty 761 Senior Poster

OK here is a little improved version of it. Now it finds at maximum of
65!. Any hints on how to find 100!

#include<iostream>
#include<fstream>
#include<cmath>
#include<iomanip>

using namespace std;
unsigned __int64 Fact(unsigned __int64 x );


int main(){

	/*n! means n  (n  1)  ...  3  2  1

Find the sum of the digits in the number 100!*/

//unsigned __int64 * fact = new unsigned __int64 (10000);

Fact(100);

}
unsigned __int64 Fact(unsigned __int64 x )
{
	unsigned __int64 * fact = new unsigned __int64 (10000);
	*fact = x;

	if(x==0)
		return 1;
	else
	{
	 *fact = x * Fact(x-1);
	 cout<<*fact<<"  "<<x<<endl;
	}

	return *fact;
	delete fact;
}
mrnutty 761 Senior Poster
#include<iostream>
#include<fstream>
#include<cmath>
#include<iomanip>

using namespace std;
unsigned __int64 Fact(unsigned __int64 x );


int main(){

	/*n! means n  (n  1)  ...  3  2  1

Find the sum of the digits in the number 100!*/


cout<<Fact(100);


}
unsigned __int64 Fact(unsigned __int64 x )
{
	__int64 num(0);

	if(x==0)
		return 1;
	else
	{
	 num = x * Fact(x-1);
	 cout<<num<<"  "<<x<<endl;
	}

	return num;
}

my recursive function works. But only for small x. (ex. 5! =120).

but when i try (100!) it runs out of space and give NULL;

so can you hint on how i can fix the code so that the computer will compute 100factorial?

mrnutty 761 Senior Poster

I see what you did but my practice problem provided by euler is to find the sum of all the digits(ex.12343 = 13 and not 5)

IN that sense I need to output 2 ^1000 untill it reaches its max significant digits.

mrnutty 761 Senior Poster

Do something with logarithms base 2.

Alright check this out. I used a little logarithm properties.

let y = 2 ^1000

then

ln (y) = ln (2^1000)

=
ln(y) = 1000 *ln(2)

take the e of both sides.

y = e^(1000*ln(2));

I know how to implement this code in c++, but can i get the most significant digits.

unsigned long double TWO=2.000;

unsigned long double expValue = (unsigned long double)log(TWO)*1000;

cout<<setprecision(5000) << (unsigned long double)exp (expValue)<<endl;

but i don't believe this would give me all the digits I need. any hints?

mrnutty 761 Senior Poster

#include<iostream>
#include<fstream>
#include<cmath>
#include<iomanip>
using namespace std;
/*
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
*/

//my logic is to export 2^1000 into a text file. Then import it into an array and the add them. but it seems to be not working as planned. any help people?

int main(){

	ofstream Ofile("num.txt");

	unsigned long double two = 2.0;
	unsigned long double oneTh = 1000.0;
	unsigned long double result = pow(two,oneTh);

	Ofile << setprecision(1000000)<<result;
	//cout<< setprecision(1000000)<<result;
	
	__int64 arry[50000]= {0};

	for(int i=0;(i<50000 && (!Ofile.eof())) ; i++ )
	{
		Ofile << arry;
		if(arry[i]<1 && (arry[i+1] && arry[i+2] == 0) ) // if a sequence of 0 starts comming break;

			break;
		cout<<arry[i];
	}



	return 0;

}
mrnutty 761 Senior Poster

So it's like i'm telling the computer to make extra memory by saying

__int64 *array = new __int64[2000000];

Is it the 'new' that tells the computer to make extra room?

mrnutty 761 Senior Poster

Static memory space is generally very limited, if you want to create large array sizes then you need to use dynamic memory.

__int64 *array = new __int64[2000000];

But be sure to delete the array afterwards

delete []array;
array = NULL; // to make sure you do not use the pointer

Chris

hmm. not sure what you mean. I know the basics about pointers but haven't learned what new is or does. Care to explain?

mrnutty 761 Senior Poster

what do u mean...ur using 32 bit compiler rit...

I mean that when i try to find the all prime numbers below 2 million,
the program corrupts, but if i try to find all prime number below say 2000, it works perfectly. Try the program to see what i mean.

I don't get why it does not work for a large number.

mrnutty 761 Senior Poster

what???

mrnutty 761 Senior Poster

hi,

I was trying to implement the sieve of eroathoses (I know I spelt this wrong) and it works. But i was trying to find all prime under 2 million.

The .cmd for visual studio just corrupts if I try to find all prime under 2million. I am guessing It's because overflow or something but I don't know for sure.

can you give me some hints on how to fix my code so the program won't corrupt. here is the code:

#include<iostream>
#include<fstream>
#include<cmath>
#include<iomanip>

using namespace std;

void sieve(__int64 arry[], __int64 upto) // finds prime num.
{	
	

	int next(0);

	for(__int64 i=0; i < upto; i++)//populate the arry starting from the value 2.
			arry[i] = i+2 ;
	
	

	for(__int64 k=1; k < upto;k++)
	{
		if(arry[k] >=1)
		{
			next = arry[k];

			for(int l = k+1 ; l <= upto ; l++)

				if(arry[l] % next==0)
					arry[l]=0;
		}
	}
		
for(__int64 i=0;i<=upto;i++)    //cout<< arry[] if it has a number greater than 0
	
	{
		if(arry[i]>0)
			cout<<arry[i]<<endl;
	}	
	
			
}

	



int main()
{
__int64 upto =200;   //This works but 2 million does not.
__int64 arry[201];    //same problem as above.

sieve(arry,upto);
 return 0;
}

thanks

mrnutty 761 Senior Poster

thanks chris

mrnutty 761 Senior Poster

Can i call a class on another class.

ex.

class a {

public: void add (int,int) ...

//maybe call class b here...///
};

class b{

public : void mult(int,int)...
};

mrnutty 761 Senior Poster

hi everyone,

I was practicing binary search with array and encountered a problem.

My code works but I can't help to make one part of it better.

Well look at my code to understand my question better.

int binary_search(int arry[], int size)
{
	int first = 0;
	int last = size;
	int middle;
	int key;

	cout<<"What number would you like to search for in the arry : ";
	cin>>key;

	for(int i=0;i<size;i++)
	
	{
			middle = ((first)+(last)) / 2;

			if(arry[middle]==key)
			{
				return middle;
				break;
			}
			else if(arry[middle] > key)
				last = middle-1;

			else if (arry[middle] < key)
				first = middle+1;
			
			 if(key > arry[last])
			 {
				cout<<"\n\n\n"<<key<<" is not in this array. \n\n"<<endl;
				exit(1);//IT IS THIS PART THAT I AM CONFUSED. I KNOW THERE IS SOME BETTER TO GO ABOUT THIS CASE THAN USING EXIT(1);
			 }
		
	}
				

}
mrnutty 761 Senior Poster

Alright. So for the first problem, about the compiler not finding the .txt file--Make sure you download/or include the file where your project is. This solution will be for visual 08.

1) open the project. Then on the left side of the screen(where you have your header file, source file..Right click on the name of the project and go to "open Folder in windows explorer. Then upload the file in the same address.


ok now for your other problems;

The function finduser is a function, that has 3 parameter. When you call the function you have to include 3 argument.

int findUser(User users[], string userID, int noOfUsers)

In your int main()
{
when you call it (ex. findUser(someArray, someString, someInt)
{
you have to use either someArray, someString, or someInt in your function. That is unless you declare another variable in your function, or have a global variable.

so try using the variables declared in the function's parameter.

hope that helps somewhat...

and Merry Christmas.

mrnutty 761 Senior Poster

Thanks I under stand.

mrnutty 761 Senior Poster

If there is anyone viewing this code , i also have one more question. do you think this code is alright. i mean if probably could be done better. what's your constructive critisicm on this?

mrnutty 761 Senior Poster

SWEET. I guess I just overlooked that. Thanks man :)

mrnutty 761 Senior Poster

I could help you write your code but I will do something even better . I will give you some hints of how to go about this so you can solve it yourself. And when you do, you will get the satisfaction of knowing that you did it and not someone else. So now here are the hints :

first to declare an arrray is the following:

datatype variable_name [constant size];

ex. int ary[100];

note:
when you declare an array of some size. its end size is its (size-1)

so on the example above the last element is ary[9];

This is so because the first element starts with 0 and not 1 ;

so to delete a last or first element you would....do something
(maybe...ary[99]=0; this would be the same as deleting)

and to insert you would ..do something. (maybe ary[0]=23;)

for the rest you should figure it out yourself. And if you still do not get it then post your problem with proof that you tried..

mrnutty 761 Senior Poster

Hello all,

I am just practicing on class. From what I have learned thus far (from the internet) I made a simple program that resembles picking a deck of cards. But my problem is that although it works. I cannot get it to generate different cards for each object. To understand better here is my code :

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

class typecard {

public:
	int displayCards();
};


//function display which cards was randomly choosen;
int typecard::displayCards()
{
	srand(time(NULL));//random number seeding;
	int card1;
	int ranCards(rand()%13+1);
	int suit(rand()%4+1);

	for(int i=0;i<5;i++)
	{
		suit = rand()%4+1;
		ranCards = rand()%13+1;
	}
		switch(ranCards)
	{	
	
		case 1:	if(suit == 1)//represents hearts.
				{
					cout<<"Ace (of hearts) ";
					card1 = 11;
				}
				if(suit == 2)//represents clubs.
				{
					cout<<"Ace (of clubs) ";
					card1 = 11;
				}
				if(suit == 3)//represents diamonds.
					{
						cout<<"Ace (of diamonds) ";
						card1 = 11;
					}
				if(suit == 4)//represents spades.
					{
						cout<<"Ace (of spades) ";
						card1 = 11;
					}
					break;

		case 2: if(suit == 1)//represents hearts.
					{
						cout<<"2 (of hearts) ";
						card1 = 2;
					}
				if(suit == 2)//represents clubs.
					{
						cout<<"2 (of clubs) ";
						card1 = 2;
					}
				if(suit == 3)//represents diamonds.
					{
						cout<<"2 (of diamonds) ";
						card1 = 2;
					}
				if(suit == 4)//represents spades.
				{
					cout<<"2 (of spades) ";
					card1 = 2;
				}
					break;

		case 3: if(suit == 1)//represents hearts.
					{
						cout<<"3 (of hearts) ";
						card1 = 3;
					}
				if(suit == 2)//represents clubs.
					{
						cout<<"3 (of clubs) ";
						card1 = 3;
					}
				if(suit == 3)//represents diamonds.
					{
						cout<<"3 (of diamonds) …
mrnutty 761 Senior Poster

I have fixed most of your problem. But your function is just missing some identifiers(ex , insted of int x, its just x)..All i did was change your header. look at it.

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

const int MAX_BOOKS = 1000;
const int MAX_USERS = 500;

enum  bookCategory 
{
    Adventure = 'A', 
    Detective = 'D', 
    SciFi = 'S', 
    Romance = 'R'
};

struct Book
{
    string bookID;
    string title;
    string authorSurname;
    string authorFirstname;
    string category;
    string location;
    string onLoan;
};

struct User
{
    string userID;
    string name;
    string houseNo;
    string address;
    string noOfLoans;
};

int findBookAuthor(Book[], string, int);

int main()
{


    fstream bookDataFile;
    fstream userDataFile;
    Book books[MAX_BOOKS];
    User users[MAX_USERS];
    int noOfBooks = 0;
    int noOfUsers = 0;
    bookDataFile.open("bookdata.txt");
    userDataFile.open("userdata.txt");

    while(!bookDataFile.eof() && noOfBooks < MAX_BOOKS) 
    { 
        getline(bookDataFile, books[noOfBooks].authorSurname );
        getline(bookDataFile, books[noOfBooks].authorFirstname );
        getline(bookDataFile, books[noOfBooks].title ); 
        getline(bookDataFile, books[noOfBooks].category),;  
        getline(bookDataFile, books[noOfBooks].bookID);      
        noOfBooks++;

    }

    while(!userDataFile.eof() && noOfUsers < MAX_USERS) 
    { 
        getline(userDataFile, users[noOfUsers].name);
        getline(userDataFile, users[noOfUsers].houseNo); 
        getline(userDataFile, users[noOfUsers].address);  
        getline(userDataFile, users[noOfUsers].userID);            
        noOfUsers++;
    }
    
    string author;
    int bookID;
    int option;
    while(true)
    {
        cout << "1. Loan Book" << endl;
        cout << "2. Find Book By Author" << endl;
        cin >> option;
        switch(option)
         {
            case 1:
                cout << "Under Construction" << endl;
            break;

            case 2:
                cout << "Enter Author Name: ";
                cin >> author;
                bookID = findBookAuthor(books, author, noOfBooks);
            break;
         }
    }    
    
    return 0;
}

int findBookAuthor(Book books[], string author, int noOfBooks)
{
    for(int bookNo = 0; bookNo < noOfBooks; bookNo++)
    {    
        if(books[bookNo].authorSurname == author)
        {
            cout << "--------------------------------------------------" << endl; …
mrnutty 761 Senior Poster

hello,

I just wanted your input on this program(can it be more efficent?...and so on ). It's a simple program. It reads 5 integers and checks if its an palindrom or not. As you can see I am a beginner.

here is my code:

#include<iostream>
//#include<string>
//#include<ctime>
//#include<cstdlib>
//#include<
using namespace std;

int main()
{
	int arry[5];//holds 5 integers;
	int checker(0);//checkes if the list os an palindrom;

	for( int i=0; i<5; i++)
	{
		cout<<"Enter a number ";
		cin>>arry[i];
	}
					
	for(int i=0,j=4;((i>=0 && i<2) && (j<=4 && j>2 ));i++,j--)
		
	{
		if(i!=j)
		{
			if(arry[i]==arry[j])
			checker++;
			
		}
	}

	if(checker==2)
				cout<<"Your number is an palindrome"<<endl;

	else cout<<"Your number is not a palindrome"<<endl;
			
	return 0;
}
mrnutty 761 Senior Poster

You could use tags. For example:
//Proper libaries//
...

ifstream  infile("text.txt")
ofstream outfile("search.txt")
...
...
...
bool tag=flase;
char Word[500];
//Searches word by word;
do 
{
   cin.getline(Word,500)

//check if word matches;
if(word[500]=="your word"
{
   tag=true;
   break;
}
} while(!infile.eof());

//So basically search the whole file and keep tab on which word you have imported and if your word matches then, break;

mrnutty 761 Senior Poster

1) The case statements need at break; statement at the end of the case to prevent other cases from being executed

case 1:
...
break;
case 2:
...
break;
// etc

2) You don't need to check the value of Deck within the case statements because that is already done in the switch statement.

3) You can't declare character arrays within if statements like that because they will disappear (go out of scope) as soon as the if statement terminates. Declare character arrays outside the switch statement so that they are in scope for the entire function.

Thanks I get that but, is there another way this can be executed, without doing this long and tedious algorithm?

mrnutty 761 Senior Poster

This code Associates each number with cards, so 1 = ace of hearts/spades/diamonds/clubs, 2 = 2 of clubs/spades..... and so on so here is the code

void DeckToCards(int Deck[]){

//Sets each element into Cards;
for(int i=0;i<52;i++)
{	
	switch(Deck[i]){
					
		case 1:{ if(Deck[i]==1 && i<14)//Clubs
					char Aces_C[]= " A (of clubs)";
				else if(Deck[i]==1 && i>13 && i<27)//Spades
					char Aces_S[]= " A (of spades) ";
				else if(Deck[i] && i>26 && i<40)//Hearts
						char Aces_H[]=" A (of hearts) ";
				else if(i>=40)//Diamonds
					char Aces_D[]=" A (of diamonds) ";
			   }

		case 2:{	if(Deck[i]==2 && i<14) // 2 of Clubs
						char 2_C[] = " 2 (of clubs";
					else if(Deck[i]==2 && i>13 && i<27)// 2 of Spades
						char 2_S[]= " 2 ( of spades)";
					else if(Deck[i]==2 && i>26 && i<40)//Hearts
						char 2_H[]= " 2 (of hearts)";
					else if(i>=40)//Diamonds
							char 2_D[]=" 2 (of diamonds)

			   }
		case 3: 
			   
	}
}

Is there any other smarter way of going about this. This code is part of a blackjack game by the way.

mrnutty 761 Senior Poster

Hehe, don't force an open door:

"AQKJ"[rand()%4]

About {1,...,10,A,Q,K,J} question: are you sure that "10" is a character? Or TWO characters? ;)

ya i know its not a character, but I guess there is no way to make a array with both character & array. Does vector work in this way?

mrnutty 761 Senior Poster

This question is for all the programmers. What makes a good prgoammers? What made you get a job? Why are you a programmer?

This is not a interview, or nothing like that. This is just someone that is curious about those question. Thank you for answer or even viewing this thread.

mrnutty 761 Senior Poster

There are alot of people that ask about card games and black jack on these forums. Why don't you search the forum and have a look over other threads solving common problems...also you can look at some example code to help you.

Chris

Than You

mrnutty 761 Senior Poster

Thanks, and I am sorry for the uneeded comment. I have another question. Is there a way to insert arry[]={1,2,3...10,J,Q,K,A}

how about using a templete?

mrnutty 761 Senior Poster

All this expert and no answer?

how about this can i somehow define a literal string with A,J,Q,K,J?
then pick it out of that or something?

mrnutty 761 Senior Poster

hi,

I wanted to know how to generate random characters, but more specifically , only A,Q,K,J. This will be for a blackjack game program.

mrnutty 761 Senior Poster

More oppions the marrier :)

mrnutty 761 Senior Poster

No more opinions?

mrnutty 761 Senior Poster

One more thing. this program supposed to be user friendly. what do you think?

mrnutty 761 Senior Poster

First off, if you want some constructive feedback my immediate question is why, (a) you are learning C++/programming for fun and decided to write some code and want to have some feed back.
(b) you are taking a class and this is to be marked, and you are hoping to improve it. (c) other...

Actually both (a) and (b) and maybe (c) are good. But it causes a difference in what I say about the code.

First off:

Is there anything that is c++ in it other than the std::cout/cin ?
There are no classes / use of the stl, etc.
If you are starting with C and moving up not a problem, for a c++ class, not so good.

Layout.... Arrh!!!!! -- That is not good.

Beyond that shuffle stands out as awful. It will not result in particularly random cards.

There are a number of exit(1) lines. This is a bit ungraceful.

The conditional breaks are very very difficult to follow. I think that is were you need to code round your logic. [I mean the if (condition) break; that litter the code.]


For this kind of task, my next step would be to write a simple command parser, so that games could be played simultaniously.
(I don't mean across computers, but command could be simple letters to start a game eg.

play B       // play blackjack
B b 50       // bet 50
B show      // show cards (again)
B card        // …
mrnutty 761 Senior Poster

The program i made below is a c++ program. All I ask for is some feedback of my program. This program has a menu of option, but I have only implemented option 1,2,3,7thus far. So here is the code.

#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;
void MemoryMatchingGame();//The matching game;
const int numberOfCards = 16;//Needed for MemoryMatching game;
void shuffle(int [], int);//Needed for MemoryMatching game;
void displayBoard(const int [], int [], int, int, int);//Needed for MemoryMatching game;
void clearScreen();//Needed for MemoryMatching game;
bool checkGameStatus(const int [], int);//Needed for MemoryMatching game;
 void menu();//The main menu;
void NUMBERgame();//The number guessing game;
void Rock_Paper_Scissors();//The rock-paper-scissors game;
void Choices();//Includes menu function with user choice needed;
int main(){

//Declare/ Initialize variables;
	int pick;

//Dunction displays menu, and inputs;
Choices();













}
void Choices()
{	int pick;
	menu();
	cout<<"Which option would you like to choose: ";
	cin>>pick;
	cout<<endl;
	while((pick<1) || (pick>7))
			{
				cout<<"Invalid input. Please input a correct response"<<endl;
				cin>>pick;
			}
	switch(pick)
	{	menu();
		cout<<"Which option would you like to choose: ";
				cin>>pick;
			while((pick<1) || (pick>7))
			{
				cout<<"Invalid input. Please input a correct response"<<endl;
				cin>>pick;
			}
		case 1: MemoryMatchingGame();
				break;
		case 2: NUMBERgame();
			    break;
		case 3: Rock_Paper_Scissors();
				break;
	    case 7: exit(1);
			    break;
	}
}
void menu()
{
	cout<<"IN THIS MENU YOU HAVE MULTIPLE CHOICES OF GAMES AND APPLICATIONS"<<endl;
	cout<<"CHOOSE THE TYPE OF GAME/APPLICATION YOU WANT TO PLAY/PICK."<<endl;
	cout<<"AFTER YOUR CHOICE, A DESCRIPTION OF THE GAME WILL POP UP"<<endl;
	cout<<"IF YOU WANT TO CONTINUE TO PLAY THE GAME AFTER READING THE DESCRIPTION, THEN FOLLOW DIRECTION FROM …