What's new

Closed C Programming Problem

Status
Not open for further replies.

pineng

Forum Veteran
Joined
May 31, 2017
Posts
1,228
Solutions
1
Reaction
2,017
Points
557
Mga boss ano bang mali dito sa program na ginamit ko please help:




#include <stdio.h>
#define twenty20 x/20
#define ten10 (x-(twenty20*20))/10
#define five5 ((x-(twenty20*20))-(ten10*10))/5
#define one1 (x-(twenty20*20))-(ten10*10))-(five5*5)/1
int main (void)
{
int x, twenty20, ten10, five5, one1;
printf("Please enter your dollar amount so we can divide it by $20, $10, $5, and $1 \n");
scanf("%d",&x);
printf("This is your distribution of dollars you put in: %d \n", twenty20);
printf("This is your distribution of dollars you put in: %d \n", ten10);
printf("This is your distribution of dollars you put in: %d \n", five5);
printf("This is your distribution of dollars you put in: %d \n", one1);
return 0;
}


lagi na ang lumakabas na error habang cincompile ko mga boss. Need help salamat
 
boss wala pa po akong alam jan mag cocollege palang po ako ganyan po ba gagawin pag mag cocomputer science?
 
Don't you have an IDE? The IDE should typically show you syntax errors. Also when you run the program the compiler should also throw something.

If you don't have one, I suggest getting one. For the meantime, you can copy and paste that code on an online C REPL like You do not have permission to view the full content of this post. Log in or register now.

The REPL shows twenty20 has been redefined and one1 has an extraneous ")"

Code:
 clang-7 -pthread -lm -o main main.c
main.c:11:8: error: redefinition of 'x'
int x, twenty20, ten10, five5, one1;
       ^
main.c:3:18: note: expanded from macro 'twenty20'
#define twenty20 x/20
                 ^
main.c:11:5: note: previous definition is here
int x, twenty20, ten10, five5, one1;
    ^
main.c:11:8: error: expected ';' at end of declaration
int x, twenty20, ten10, five5, one1;
       ^
main.c:3:19: note: expanded from macro 'twenty20'
#define twenty20 x/20
                  ^
main.c:13:88: error: expected ')'
  ...amount so we can divide it by $20, $10, $5, and $1 \n";
                                                           ^
main.c:13:7: note: to match this '('
printf("Please enter your dollar amount so we can divide it b...
      ^
main.c:19:70: error: extraneous ')' before ';'
  ...is your distribution of dollars you put in: %d \n", one1);
                                                             ^
4 errors generated.
compiler exit status 1

ALSO use the code tags so we can read your code better!
 
#define is used to initialize or define a constant variable.
Values of constant variables remain the same and can't be change throughout the program.

Your twenty20, ten10, five5, and one1 are not constants because their values are derive from x.
And it seems that the value of x is coming from the user, therefore the computation of their value should come after that.

You should do it like this:

Code:
#include <stdio.h>


int main (void)

{

int x, twenty20, ten10, five5, one1;


printf("Please enter your dollar amount so we can divide it by $20, $10, $5, and $1 \n");

scanf("%d",&x);


// Insert dollars computation


printf("This is your distribution of dollars you put in: %d \n", twenty20);

printf("This is your distribution of dollars you put in: %d \n", ten10);

printf("This is your distribution of dollars you put in: %d \n", five5);

printf("This is your distribution of dollars you put in: %d \n", one1);

return 0;

}
 
A simple google and basic reading about C usage would had resolve all these concerns.

I am surprised you are focusing with C though.
 
okay. Am I on a good track?
okay. Am I on a good track?

D naman curious ka lang cguro sa mga declaration atleast nagttry ka.Ito lang naman critical sa ginawa mo.Assignment nyo to?Ano yung question?

#define twenty20 x/20
#define ten10 (x-(twenty20*20))/10
#define five5 ((x-(twenty20*20))-(ten10*10))/5
#define one1 (x-(twenty20*20))-(ten10*10))-(five5*5)/1

Pwede naman icompute pagkatapos ng scanf para mas madali, pero nakadepende yan sa structure kung pano yung flow ng program. Nacurious ka lang siguro sa instruction na binigay sau.Baka pinapagawa ka ng functions.

Float five5 (int x)
....
..

Better start ka muna pagaralan yung mga types,variable and fuctions library.
 
Last edited:
D naman curious ka lang cguro sa mga declaration atleast nagttry ka.Ito lang naman critical sa ginawa mo.Assignment nyo to?Ano yung question?

#define twenty20 x/20
#define ten10 (x-(twenty20*20))/10
#define five5 ((x-(twenty20*20))-(ten10*10))/5
#define one1 (x-(twenty20*20))-(ten10*10))-(five5*5)/1

Pwede naman icompute pagkatapos ng scanf para mas madali, pero nakadepende yan sa structure kung pano yung flow ng program. Nacurious ka lang siguro sa instruction na binigay sau.Baka pinapagawa ka ng functions.

Float five5 (int x)
....
..

Better start ka muna pagaralan yung mga types,variable and fuctions library.
di po assignment sir, nag aadvance study po ako :) Sa book ko po yan kinuha. KN King C programming
 
Ganito dapat declaration mo

#define get20 (x) x/20

Then do the rest gl.


Here sample You do not have permission to view the full content of this post. Log in or register now.

D lumabas yung result i forgot getchar

getch ();
return 0;
 
Last edited:
Status
Not open for further replies.

Similar threads

Back
Top