I just can't figure out why my codes can't be compiled successfully . Anyone can help ?
The main :
#include <iostream>
#include "header.h"
#include <ctime>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std ;
int main()
{
int unwin[] = {0,0,0,0} , problem = 0 ;
ACCOUNT acc1("Steven Lo " , 1000) ;
srand(time(0)) ;
while(true)
{
menu(acc1, unwin , problem) ;
if (acc1.balance < 5)
{cout << "Game Over" << endl ;
break ;
}
}
return 0 ;
}
The header file :
class DATA
{
public :
void set_draw(int &problem) ;
void random_draw() ;
void sorting_draw() ;
int draw[6] ;
}
;
class ACCOUNT
{
private :
char name[50] ;
public :
DATA gaming ;
double balance ;
ACCOUNT(char a[] , double b)
{
for ( int i = 0 ; i < 50 ; i++)
name[i] = a[i] ;
balance = b ;
}
void set_name() ;
void set_balance(double ) ;
void display_name() ;
};
void menu(ACCOUNT &acc1 , int unwin[] , int &problem) ;
void Account_details(ACCOUNT &acc1);
void Prizes(int []);
void Select_Account();
void play(ACCOUNT &acc1 , int [] , int &problem);
void display_name() ;
void sorting(int [])
The functional file :
#include <iostream>
#include "header.h"
#include <ctime>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std ;
void DATA::set_draw(int &problem)
{
for ( int i = 0 ; i < 6 ; i++)
{
cout << " The "<<i+1<<" no. is " ;
cin>> draw[i] ;
cout<<" " ;
}
for ( int i = 0 ; i <6 ; i++)
{
if ( draw[i] < 1 || draw[i] > 49)
{cout << "Invalid no. !!!! ( Number Chosen should be in the range of integers from 1 to 49 )" <<endl ;
problem = 1 ;
return ;
}
for ( int j = i + 1 ; j < 6 ; j ++ )
{
if ( i == 5 )
break ;
if ( draw[i] == draw[j] )
{
cout << "Repeated Number ! " << endl ;
problem = 1 ;
return ;
}
}
}
sorting_draw() ;
cout << " The Numbers you chosen are " ;
for ( int i = 0 ; i < 6 ; i++)
cout << draw[i] << " " ;
cout << endl ;
}
void DATA::random_draw()
{
for (int i = 0 ; i < 7 ; i ++)
draw[i] = rand() % 49 + 1 ;
for ( int i = 0 ; i <7 ; i ++ )
{
for (int j = i+1 ; j < 7 ; j++)
{
if ( i == 6 )
break ;
if ( draw[j] == draw[i] )
{draw[j] = rand() % 49 + 1 ;
i = -1 ;
break ;
}
}
}
sorting_draw() ;
cout << " The Numbers you chosen are " ;
for ( int i = 0 ; i < 6 ; i++)
cout << draw[i] << " " ;
cout << endl ;
}
void menu(ACCOUNT &acc1 , int unwin[] , int &problem)
{
int num ;
cout << "Welcome to Lucky Draw Game !"<<endl ;
cout << "1. Account details and configurations"<<endl ;
cout << "2. Prizes for coming game"<<endl ;
cout << "3. select account "<<endl ;
cout << "4. Play"<<endl ;
cout << "5. Exit" << endl ;
cout << "Please Enter choice ( 1 - 5 ) : " ;
cin>> num ;
cout << endl <<endl ;
if ( num == 1)
Account_details(acc1) ;
else if (num == 2)
Prizes(unwin) ;
else if (num==3)
Select_Account() ;
else if (num == 4 )
play(acc1 , unwin , problem) ;
else if (num == 5)
exit(1) ;
else
cout << " Invalid !!!!!!!!!!!!!!!" << endl ;
}
void Account_details(ACCOUNT &acc1)
{
int x ;
cout << "Account details and configurations : " << endl ;
cout << "1. Account details "<<endl ;
cout << "2. Account name configuration"<<endl ;
cout << "Please make a choice : " ;
cin >> x ;
cout << endl << endl ;
if ( x == 1 )
acc1.display_name() ;
else if ( x == 2 )
acc1.set_name() ;
else
cout << " Invalid !!!!" << endl<<endl ;
}
void play(ACCOUNT &acc1 , int unwin[] , int &problem)
{
int result[7] , bingo = 0 , x;
cout << " Which way of gambling are you prefering to ? " << endl ;
cout << " 1 . By my own choice " << endl ;
cout << " 2 . By random generation " << endl ;
cout << " I choose (1-2) : " << endl ;
cin>>x ;
if ( x == 1 )
acc1.gaming.set_draw(problem) ;
else if ( x == 2 )
{
acc1.gaming.random_draw() ;
}
else
{cout << " Wrong Input . " << endl<<endl ;
return ;
}
if (problem == 1)
{
problem = 0 ;
return ;
}
acc1.balance = acc1.balance - 5 ;
for (int i = 0 ; i < 7 ; i ++)
result[i] = rand() % 49 + 1 ;
for ( int i = 0 ; i <7 ; i ++ )
{
for (int j = i+1 ; j < 7 ; j++)
{
if ( i == 6 )
break ;
if ( result[j] == result[i] )
{result[j] = rand() % 49 + 1 ;
i = -1 ;
break ;
}
}
}
sorting(result) ;
cout << " The Result are " ;
for ( int i = 0 ; i < 6 ; i++)
cout << result[i] << " " ;
cout << endl ;
cout << " Special Number Is " << result[6] << endl ;
cout << endl ;
for ( int i = 0 ; i < 6 ; i ++)
{for (int j = 0 ; j <6 ; j++)
{
if ( result [i] == acc1.gaming.draw[j] )
bingo ++ ;
}
}
if ( bingo == 3 )
{acc1.set_balance(20.0) ;
cout << " You have won " << 20 << " Dollars !!!! Please check your account . " << endl << endl ;
return ;}
else if ( bingo == 4)
{ acc1.set_balance(5000 * (pow (1+ 0.005 * unwin[2],1+ 0.005 * unwin[2]))) ;
cout << " You have won " << 5000 * (pow (1+ 0.005 * unwin[2],1+ 0.005 * unwin[2])) << " Dollars !!!! Please check your account . " << endl << endl ;
unwin[2] = 0 ;
return ;
}
else if (bingo == 5)
{
acc1.set_balance(250000 * (pow (1+ 0.005 * unwin[1],1+ 0.005 * unwin[1]))) ;
cout << " You have won " << 250000 * (pow (1+ 0.005 * unwin[1],1+ 0.005 * unwin[1])) << " Dollars !!!! Please check your account . " << endl << endl ;
unwin[1] = 0 ;
return ;
}
else if (bingo == 6)
{
acc1.set_balance(1000000 *(pow (1+ 0.005 * unwin[0],1+ 0.005 * unwin[0]))) ;
cout << " You have won " << 1000000 *(pow (1+ 0.005 * unwin[0],1+ 0.005 * unwin[0])) << " Dollars !!!! Please check your account . " << endl << endl ;
unwin[0] = 0 ;
return ;
}
cout << " Sorry that you haven't won a prize . Wish you can win a prize in the coming games anyway !" <<endl << endl ;
for ( int i = 0 ; i < 4 ; i++)
unwin[i] ++ ;
}
void ACCOUNT::set_name()
{
string temp ;
cout << "Please Enter an account name : " ;
cin>> temp ;
if ( temp.length() > 50 )
cout << "out of bound !!!!" << endl <<endl ;
else if (temp.length() <= 50 || temp.length() >=0)
{for ( int i = 0 ; i < temp.length() ; i ++)
name[i] = temp[i] ;
for ( int i = temp.length() ; i < 50 ; i ++)
name[i] = ' ' ;
}
cout << endl<<endl ;
}
void ACCOUNT::display_name()
{cout << "Account name : " ;
for ( int i = 0 ; i < 50 ; i ++)
cout << name[i] ;
cout<<endl ;
cout << "Account Balance : " << balance << endl << endl ;
}
void sorting(int a[])
{
int temp = a[0] , count = 0 , min_index = 0 ;
for ( int i = 0 ; i < 6 ; i++)
{
if ( a[i] < temp )
{
temp = a[i] ;
min_index = i ;
}
if ( i == 5 )
{
temp = a[count];
a[count] = a[min_index] ;
a[min_index] = temp ;
count ++ ;
min_index = count ;
temp = a[min_index] ;
i = count ;
}
}
}
void DATA::sorting_draw()
{
int temp = draw[0] , count = 0 , min_index = 0 ;
for ( int i = 0 ; i < 6 ; i++)
{
if ( draw[i] < temp )
{
temp = draw[i] ;
min_index = i ;
}
if ( i == 5 )
{
temp = draw[count];
draw[count] =draw[min_index] ;
draw[min_index] = temp ;
count ++ ;
min_index = count ;
temp = draw[min_index] ;
i = count ;
}
}
}
Here's what the compiler said :
1>------ Build started: Project: header and class application, Configuration: Debug Win32 ------
1> lucky draw.cpp
1>d:\microsoft visual studio 10.0\vc\include\time.h(35): error C2144: syntax error : 'int' should be preceded by ';'
1>c:\users\steven\documents\visual studio 2010\projects\header and class application\header and class application\lucky draw.cpp(13): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1> function.cpp
1>d:\microsoft visual studio 10.0\vc\include\time.h(35): error C2144: syntax error : 'int' should be preceded by ';'
1>c:\users\steven\documents\visual studio 2010\projects\header and class application\header and class application\function.cpp(216): warning C4018: '<' : signed/unsigned mismatch
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========