Hi everyone. This is my first post . I develop this program in C-Free 4.0 with <iostream> header... And it working

#include <iostream>
#include <cstdlib> 
#include <iomanip>
#include <ctime>

using namespace std;
int main ()
{    
    
    int random_num;
    srand((unsigned)time(0));
    
    bool assigned_players[32];
    
    for (int i=0;i<32;i++)
        assigned_players[i] = false;
        
    int n=32;
    cout<<"Game    Players"<<endl;
    while (n>0){
        random_num = (rand()%(32))+1;
        if (!assigned_players[random_num-1]){
            if ((32-n)%2==0){
                cout<<(32-n)/2+1;
                if (((32-n)/2+1)>9)
                    cout<<setw(8)<<random_num;
                else
                    cout<<setw(9)<<random_num;
            }
            
            if ((32-n)%2==1)
                cout<<" - "<<random_num<<endl;
            
            assigned_players[random_num-1] = true;
            
                
            n--;
        }
    }
        

    return 0;
}

But when i rebuild it without <iostream> header. It came up with some errors. Can any please help me? Thanks you:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define SIZE 32
int main (void)
{
double x[SIZE];
int random_number;
int i, n;
srand((unsigned) time(0));
for (i=0;i<32;i++);
        x[i] = "false";
n=32;
Printf("Game    Player\n");

while (n>0){
        random_number = (rand()%(32))+1;
        if (!x[random_number-1]){
            if ((32-n)%2==0){
                printf("(32-n)/2+1\n");
                if (((32-n)/2+1)>9)
                    printf("%d\n",random_number);
                else
                    printf("%d\n",random_number);
            }
            
            if ((32-n)%2==1)
                printf("-\n",random_number);;
            
            x[random_number-1] = "true";
            
                
            n--;
        }
    }
        

    return 0;
}

Error is:
Checking file dependency...
Compiling C:\Program Files (x86)\C-Free 4\temp\Untitled1.cpp...
[Error] C:\Program Files (x86)\C-Free 4\temp\Untitled1.cpp:13: assignment to `double' from `const char *'
[Error] C:\Program Files (x86)\C-Free 4\temp\Untitled1.cpp:15: implicit declaration of function `int Printf(...)'
[Error] C:\Program Files (x86)\C-Free 4\temp\Untitled1.cpp:31: assignment to `double' from `const char *'

Recommended Answers

All 7 Replies

Why are you trying to store the strings "false" and "true" into double variables?

And where did you define Printf()?

This is my fixed code. But still have some errors:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define SIZE 32
int main (void)
{
    double x[SIZE];
    int random_number;
    int i, n;
    srand((unsigned) time(0));
    
    for (i=0;i<SIZE;i++)
        x[i] = false;
    n=32;
    printf("Game    Player\n");

while (n>0){
        random_number = (rand()%(32))+1;
        if (!x[random_number-1]){
            if ((32-n)%2==0){
                printf("%2d      ",(32-n)/2+1);
                printf("%2d ",random_number);
            }
           
            if ((32-n)%2==1)
                printf("- %2d\n",random_number);;
           
            x[random_number-1] = true;
           
               
            n--;
        }
    }
       

    return 0;
}

error: ‘false’ undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: ‘true’ undeclared (first use in this function)

false and true are not defined in C. You need to define them.

Sorry I just started with c++, can you help me how can i define true and false, please? thanks you

If you are trying to learn C++ why are you concerned with making a C program?

It is never wrong to start learning C when you want to pick up C++ skills. After all, C++ is the superset of C. Through this, you will be able to differentiate between both of them. For 'true' and 'false' are not defined in C language, you may want to define them through the macro #define.

Normally, programmers utilize integers to represent true and false values like:-

#define FALSE 0
#define TRUE 1

Where having a value zero always mean false.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.