francisco123 Posted September 30, 2012 at 11:50 AM Report #477149 Posted September 30, 2012 at 11:50 AM (edited) Tenho uma função Game que retorna a variavel pc e a variavel pc é um valor double calculado dentro dessa função. Agora eu tenho outra função chamada Color que vai fazer uns cálculos com o valor da variavel pc calculada na variavel Game. Como posso usar o valor da variavel pc na função Color? Obrigado Edited September 30, 2012 at 11:55 AM by pmg ajuste depois de split de topico
pmg Posted September 30, 2012 at 11:58 AM Report #477150 Posted September 30, 2012 at 11:58 AM Se tens uma questao nova faz um topico novo. Assim ficam os topicos organizados por tema e torna a gestao, e procura mais facil. Nao percebi bem a tua duvida. Se a funcao devolve o valor que queres, mete-o numa variavel e usa-o. Estou a ver alguma coisa errada? ??? int Game(void) { return 42; } void Color(void) { int pc = Game(); /* usa pc */ } What have you tried? Não respondo a dúvidas por PM A minha bola de cristal está para compor; deve ficar pronta para a semana. Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!
AJBM Posted September 30, 2012 at 11:59 AM Report #477151 Posted September 30, 2012 at 11:59 AM Boas!! Podes declarar uma variável dentro da função color, por exemplo double pcValor= Game(); ou podes usar a função Game() directamente.
Flinger Posted October 1, 2012 at 09:01 AM Report #477282 Posted October 1, 2012 at 09:01 AM mais uma alternativa.... int game() { return 42; } int color(int g) { do_something(g); return 0; } int main(void) { int gamevalue=0; gamevalue=game(); color(gamevalue); }
HappyHippyHippo Posted October 1, 2012 at 09:39 AM Report #477288 Posted October 1, 2012 at 09:39 AM (edited) alernativa N : void game(int * i_am_pointing_to_a_value) { *i_am_pointing_to_a_value = 42; } void color(int * i_am_pointing_to_a_value) { *i_am_pointing_to_a_value /= 2; } int main() { int value = 0; game(&value); color(&value); return 0; } alternativa N+1: void game(int * i_am_pointing_to_a_value) { *i_am_pointing_to_a_value = 42; } void color(int * i_am_pointing_to_a_value) { *i_am_pointing_to_a_value /= 2; } int main() { int * i_will_point_to_a_value; if ((i_will_point_to_a_value = malloc(sizeof int)) == NULL) exit(-1); game(i_will_point_to_a_value); color(i_will_point_to_a_value); free(i_will_point_to_a_value); return 0; } alternativa N+2: int * game() { int * please_free_me_in_the_future; if ((please_free_me_in_the_future = malloc(sizeof int)) == NULL) return NULL; *please_free_me_in_the_future = 42; return please_free_me_in_the_future; } void color(int * i_will_be_free) { printf("%d\n", i_will_be_free); free(i_will_be_free); } int main() { int * memory; if ((memory = game()) == NULL) exit(-1); color(memory); return 0; } alternativa N+3: int please_dont_use_this_alternative = 0; void game() { please_dont_use_this_alternative = 42; } void color() { printf("%d\n", please_dont_use_this_alternative); } int main() { game(); color(); } Edited October 1, 2012 at 10:10 AM by pmg Murphy's Law (havia um "void main()") IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now