Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Velcis Ribeiro

Erro convertendo 'int from 'double' ?

Recommended Posts

# include <stdlib.h>
# include <stdio.h>
# include <math.h>

int a,b,c,t,e,f,tt;
int main(){
    


       printf("Diga um valor para A :  ");
           scanf("%i", &a);
           
                printf("Diga um valor para B :  ");
           scanf("%i", &B);
                printf("Diga um valor para C :  ");
           scanf("%i", &c);
           e=fabs(a-B);
           t=((a+B)+e)/2;
           f=fabs(t-c);
           tt=((t+c)+f)/2;
           
           printf("O maior numero eh %i . \n", tt);
           system("pause");
           
}
Gente tou com o seguinte problema, ja tentei mudar de int para float ou para double e continua este erro.

 

17 C:\..s\Problema 13.cpp [Warning] converting to `int' from `double'

19 C:\..s\Problema 13.cpp [Warning] converting to `int' from `double'

 

Se puderem ajudem, obrigado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Isso não é um erro. O compilador só está avisando que há perda de precisão.

 

E antes que você saia usando %i em tudo quanto é canto:

 

d Matches an optionally signed decimal integer, whose format is the same as expected for the subject sequence of strtol() with the value 10 for the base argument. In the absence of a size modifier, the application shall ensure that the corresponding argument is a pointer to int.

 

i Matches an optionally signed integer, whose format is the same as expected for the subject sequence of strtol() with 0 for the base argument. In the absence of a size modifier, the application shall ensure that the corresponding argument is a pointer to int.

Compartilhar este post


Link para o post
Compartilhar em outros sites

XD ja respondeu a questão e nem vi http://forum.imasters.com.br/public/style_emoticons/default/joia.gif

tira o 1º fabs q da certo ja :D

 

aqui...

# include <stdlib.h>
# include <stdio.h>
# include <math.h>

int a,b,c;
double maior;
int main(){

printf("Diga um valor para A : ");
scanf("%i", &a);

printf("Diga um valor para B : ");
scanf("%i", &B);
printf("Diga um valor para C : ");
scanf("%i", &c);
maior =(((a+B)+fabs(a-B))/2);
maior =(((maior+c)+fabs(maior-c))/2);
printf("o maior = %5.5f\n\n",maior);
system("pause");

}

 

sorry por não ter visto esse antes de responde ...

 

espero ter ajudado...

 

bye

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não é a presença ou ausência da função que "dá certo". Olhe a diferença entre o seu código e o dele nos tipos usados.

Outro detalhe: isso é C. Não salve com extensão cpp. E não use variáveis globais.

Compartilhar este post


Link para o post
Compartilhar em outros sites

hum tendeu...

mas tem diferença em declara dentro ou fora do main mesmo ñ tendo outra função???

 

as variaveis eu coloquei as que eu tinha falado no outro topico q ele tinha perguntado fico um pouco mais legivel digamos assim ...rs

 

flwwww

Compartilhar este post


Link para o post
Compartilhar em outros sites

Variáveis globais são definidas numa seção .globl do assembly, com declarações de alinhamento de memória e tamanho:

.globl a

.data

.align 4

.type a, @object

.size a, 4

a:

.long 2

.globl c

.align 4

.type c, @object

.size c, 4

c:

.long 3

.text

 

O código com a declaração local fica assim:

 

.file "lc.c"

.text

.globl main

.type main, @function

main:

leal 4(%esp), %ecx

andl $-16, %esp

pushl -4(%ecx)

pushl %ebp

movl %esp, %ebp

pushl %ecx

subl $16, %esp

movl $2, -12(%ebp)

movl $3, -8(%ebp)

movl $0, %eax

addl $16, %esp

popl %ecx

popl %ebp

leal -4(%ecx), %esp

ret

 

Sem falar no escopo das variáveis...

int a=2, c=3;
int main() {
int a;
a = 9;
return 0;
}

 

Esse código não sobrescreve a variável global, mas cria uma outra variável 'a' local em main e atribui '9'.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.