Parece ser que o mis condiciones no estan bien expresadas o mi printf no es el apropiado C++



   AUTOR PREGUNTA

Publicado 05 septiembre 2018 - 01:39

Aqui esta el enunciado: Haga un diagrama de flujo que permita calcular el valor de f(x) según la expresión:

 

x^2 si (xmod4)=0

x/6 si (xmod4)=1

x^(1/2) si (xmod4)=2

x^3 + 5 si (xmod4)=3

 

Deacuerdo a lo anterior, se me ha ocurrido lo siguiente:

 

#include <stdio.h>
 
main(){
int x,f1,f2,f3,f4=0;
  
printf("Ingrese x");
scanf("%d",&x);
  
f1=x^2;
f2=x/6;
f3=x^(1/2);
f4=x^3+5;
  
if(x%4==0){
printf("%d",&f1);
}
else{
if(x%4==1){
printf("%d",&f2);
}
else{
if(x%4==2){
printf("%d",&f3);
}
else{
if(x%4==3){
printf("%d",&f4);
}
else{
printf("No valido");
}
}
}
}
}



¿Tienes la misma pregunta? Yo también

 

Publicado 07 septiembre 2018 - 10:54

Hola Benedict usa un compilador de este tipo para ayudarte en los errores.

 

Por favor Identificate o Registrate para poder ver este contenido

 

En tu caso saltan todos estos:

 

main.c:1:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘^’ token
x^2 si (xmod4)=0
^
In file included from /usr/include/stdio.h:74:0,
from main.c:15:
/usr/include/libio.h:306:3: error: unknown type name ‘size_t’
size_t __pad5;
^
/usr/include/libio.h:310:67: error: ‘size_t’ undeclared here (not in a function)
char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
^
/usr/include/libio.h:338:62: error: expected declaration specifiers or ‘...’ before ‘size_t’
typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
^
/usr/include/libio.h:347:6: error: expected declaration specifiers or ‘...’ before ‘size_t’
size_t __n);
^
/usr/include/libio.h:469:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_IO_sgetn’
extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t);
^
In file included from main.c:15:0:
/usr/include/stdio.h:337:20: error: expected declaration specifiers or ‘...’ before ‘size_t’
int __modes, size_t __n) __THROW;
^
/usr/include/stdio.h:386:44: error: expected declaration specifiers or ‘...’ before ‘size_t’
extern int snprintf (char *__restrict __s, size_t __maxlen,
^
/usr/include/stdio.h:390:45: error: expected declaration specifiers or ‘...’ before ‘size_t’
extern int vsnprintf (char *__restrict __s, size_t __maxlen,
^
/usr/include/stdio.h:709:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
extern size_t fread (void *__restrict __ptr, size_t __size,
^
/usr/include/stdio.h:715:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
extern size_t fwrite (const void *__restrict __ptr, size_t __size,
^
In file included from /usr/include/stdio.h:937:0,
from main.c:15:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:23:61: error: expected declaration specifiers or ‘...’ before ‘size_t’
extern int __sprintf_chk (char *__restrict __s, int __flag, size_t __slen,
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h:25:62: error: expected declaration specifiers or ‘...’ before ‘size_t’
extern int __vsprintf_chk (char *__restrict __s, int __flag, size_t __slen,
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h:52:50: error: expected declaration specifiers or ‘...’ before ‘size_t’
extern int __snprintf_chk (char *__restrict __s, size_t __n, int __flag,
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h:53:7: error: expected declaration specifiers or ‘...’ before ‘size_t’
size_t __slen, const char *__restrict __format,
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h:55:51: error: expected declaration specifiers or ‘...’ before ‘size_t’
extern int __vsnprintf_chk (char *__restrict __s, size_t __n, int __flag,
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h:56:8: error: expected declaration specifiers or ‘...’ before ‘size_t’
size_t __slen, const char *__restrict __format,
^
In file included from /usr/include/features.h:374:0,
from /usr/include/stdio.h:27,
from main.c:15:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:61:1: error: expected declaration specifiers or ‘...’ before ‘size_t’
__NTH (snprintf (char *__restrict __s, size_t __n,
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h:74:1: error: expected declaration specifiers or ‘...’ before ‘size_t’
__NTH (vsnprintf (char *__restrict __s, size_t __n,
^
In file included from /usr/include/stdio.h:937:0,
from main.c:15:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:227:39: error: expected declaration specifiers or ‘...’ before ‘size_t’
extern char *__gets_chk (char *__str, size_t) __wur;
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h:241:49: error: expected declaration specifiers or ‘...’ before ‘size_t’
extern char *__fgets_chk (char *__restrict __s, size_t __size, int __n,
^
In file included from /usr/include/features.h:374:0,
from /usr/include/stdio.h:27,
from main.c:15:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:246:14: error: expected declaration specifiers or ‘...’ before ‘size_t’
extern char *__REDIRECT (__fgets_chk_warn,
^
In file included from /usr/include/stdio.h:937:0,
from main.c:15:
/usr/include/x86_64-linux-gnu/bits/stdio2.h: In function ‘fgets’:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:260:20: error: expected ‘)’ before ‘__n’
if ((size_t) __n > __bos (__s))
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h: At top level:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:266:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__fread_chk’
extern size_t __fread_chk (void *__restrict __ptr, size_t __ptrlen,
^
In file included from /usr/include/features.h:374:0,
from /usr/include/stdio.h:27,
from main.c:15:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:269:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__fread_alias’
extern size_t __REDIRECT (__fread_alias,
^
/usr/include/x86_64-linux-gnu/bits/stdio2.h:273:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__fread_chk_warn’
extern size_t __REDIRECT (__fread_chk_warn,
^
In file included from /usr/include/stdio.h:937:0,
from main.c:15:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:282:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
fread (void *__restrict __ptr, size_t __size, size_t __n,
^
main.c:17:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
main(){
^
main.c: In function ‘main’:
main.c:29:8: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]
printf("%d",&f1);
^
main.c:33:8: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]
printf("%d",&f2);
^
main.c:37:8: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]
printf("%d",&f3);
^
main.c:41:8: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]
printf("%d",&f4);
^
main.c:21:1: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&x);
^