Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

c++ help

skatoulis100skatoulis100 Member Posts: 3
please help me... i made a problem in c and i want to convert it to c++ please help me..if you can conver it that is the programme

#include
#include
#include

int main(){
int i,j;
float max,temp;
long size;
char *ch = malloc(6*sizeof(char));
char *line = malloc(128*sizeof(char));
char delims[] = " ";
char *result = NULL;
char out[10];
FILE *fp;

fp = fopen("profit.in","r");
fseek(fp,0,SEEK_SET);
do{
fgets(ch,sizeof(ch),fp);
size = atoi(ch);
}while(size<=0 && size >=1000000 );

float *array = malloc(size*sizeof(float));
i = 0;
while (fgets(line,sizeof(line),fp)!=NULL){
result = strtok( line, delims );
while( result != NULL ) {
array[i] = atoi(result);

result = strtok( NULL, delims );
i++;
}
}

fclose(fp);
max=-1.000;
for(i=0;i=i;j--){
temp=array[j]/array[i];
if(temp>max)
max=temp;
}
}
sprintf(out,"%0.3f",max);

fp = fopen("profit.out","w");
fputs(out,fp);
fputs("
",fp);
fclose(fp);
return 0;}

Comments

  • HK_MP5KPDWHK_MP5KPDW Member Posts: 770 ✭✭✭
    Please use code tags when posting code and properly format/indent for readability purposes. Easiest thing to do is to highlight your relevant code (code only, not the entire post) and then click on the button that looks like <> and it will put the tags around the highlighted text for you automatically.

    Here is what it looks like with code tags (and formated):
    [code]#include
    #include
    #include

    int main()
    {
    int i,j;
    float max,temp;
    long size;
    char *ch = malloc(6*sizeof(char));
    char *line = malloc(128*sizeof(char));
    char delims[] = " ";
    char *result = NULL;
    char out[10];
    FILE *fp;

    fp = fopen("profit.in","r");
    fseek(fp,0,SEEK_SET);
    do{
    fgets(ch,sizeof(ch),fp);
    size = atoi(ch);
    }while(size<=0 && size >=1000000 );

    float *array = malloc(size*sizeof(float));
    i = 0;
    while (fgets(line,sizeof(line),fp)!=NULL){
    result = strtok( line, delims );
    while( result != NULL ) {
    array[i] = atoi(result);

    result = strtok( NULL, delims );
    i++;
    }
    }

    fclose(fp);
    max=-1.000;
    for(i=0;i=i;j--){
    temp=array[j]/array[i];
    if(temp>max)
    max=temp;
    }
    }
    sprintf(out,"%0.3f",max);

    fp = fopen("profit.out","w");
    fputs(out,fp);
    fputs("
    ",fp);
    fclose(fp);
    return 0;
    }
    [/code]
    Isn't that much better!

    Now, if you want to have it converted it would be best to make some attempt at doing this instead of simply posting it and asking someone else to do it for you. If you have specific questions about what to use in place of existing code then please go ahead. We can provide support/assistance and point out problem areas you may be having difficulties with.
Sign In or Register to comment.