Announcement

Collapse
No announcement yet.

Need some pointers in C programming

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need some pointers in C programming

    Well I'm my first programming class with my online program and I need to write a program in C that displays how much US currency is over 5 other currencies. I need to input a number and give the answer of how much the US Dollar is vs 5 other currencies.

    Any care to give me any hints? My only other experience is with modifying the typical Hello World in C
    Why is it called tourist season, if we can't shoot at them?

  • #2
    Originally posted by GT98
    Well I'm my first programming class with my online program and I need to write a program in C that displays how much US currency is over 5 other currencies. I need to input a number and give the answer of how much the US Dollar is vs 5 other currencies.

    Any care to give me any hints? My only other experience is with modifying the typical Hello World in C
    Need to know what you already have. If any of us help you too much with this relatively simple assignment, you'll never learn ANYTHING.
    The Internet - where men are men, women are men, and teenage girls are FBI agents!

    I'm the least you could do
    If only life were as easy as you
    I'm the least you could do, oh yeah
    If only life were as easy as you
    I would still get screwed

    Comment


    • #3
      I have nothing at the moment...they have us using C programing for the absolute beginner as our txt and I was looking at it and so far its not making any sense to me...then again it is focusing on my worse subjects....math and language

      I just need a bit of code to go on to play with and figure out..
      Why is it called tourist season, if we can't shoot at them?

      Comment


      • #4
        well write out the math bit to get started, then work how that would be represented in C

        from there you have to get input values into the program for the calculations

        And then finally show the results. The "hello world" program should help for that bit

        Comment


        • #5
          Yikes. It sounds like you just don't know... uh... anything about programming. Have you not been paying attention in class? I'm not being mean, but this is really like someone showing up with a copy of "Catcher in the Rye" and an assignment to write an outline of the third chapter... and then saying "well but I don't know what any of these words are" and you find out they can't read.
          The Internet - where men are men, women are men, and teenage girls are FBI agents!

          I'm the least you could do
          If only life were as easy as you
          I'm the least you could do, oh yeah
          If only life were as easy as you
          I would still get screwed

          Comment


          • #6
            I agree with the above...

            In general, you first need to assess what the program should do (read input, the math, print output).
            Next, you need to determine which variables you need (and what their type should be)

            Then you can start programming: declare the variables, add the math, and write the output.


            Jorg
            pixar
            Dream as if you'll live forever. Live as if you'll die tomorrow. (James Dean)

            Comment


            • #7
              in a beginners program, look up what scanf and printf can do.. or if you are doing it in the more modern C++ style, look up cin and cout
              We have enough youth - What we need is a fountain of smart!


              i7-920, 6GB DDR3-1600, HD4870X2, Dell 27" LCD

              Comment


              • #8
                Originally posted by Gurm
                Yikes. It sounds like you just don't know... uh... anything about programming. Have you not been paying attention in class? I'm not being mean, but this is really like someone showing up with a copy of "Catcher in the Rye" and an assignment to write an outline of the third chapter... and then saying "well but I don't know what any of these words are" and you find out they can't read.

                Well its hard not to pay attention in class when its a online course. I've read chapter of of the text and was able to do a quick and dirty program by modifing the Hello World program that they give you...I've read chapter two of the book and was like huh when I went though it for the most part, but I do understand that I need to get the math part figured out first..which isnt too hard. I have till monday to figure it out so I guess I better start getting some sort of code up to get it figured out LOL
                Why is it called tourist season, if we can't shoot at them?

                Comment


                • #9
                  Well look here's a starting point...

                  C uses what is called "grammar". All programming languages do, it's why they're called "languages"! In a C program, you have "structures". Each structure is demarcated from other structures using curly braces { }. That the type of structure is demarcated by a TAG preceding the curly braces, and that (optional) PARAMETERS of the structure go between the tag and the braces inside of parentheses ( ), and that any (optional) type modifiers (more on that later) of the structure go just before the tag. In general, it looks like this:

                  modifier tag ( parameter list )
                  {
                  code
                  }

                  We also learn that each standalone line of code must be followed with a semicolon ;

                  That's the basic GRAMMAR of C. Now let's look at how that's applied with some examples:

                  void main ( )
                  {
                  printf ("Hello world!\n");
                  }

                  That was easy, right? Of course it was. If a tag isn't a "reserved word" such as a variable type, the word VAR for variable, or a built-in function name, it is assumed to be a user-defined function name. However, "main" is a reserved name for the primary function of your program. Therefore that structure is the MAIN FUNCTION of your program. The type modifier is "void", which means that the program doesn't have a "value" of any kind (strictly speaking it's only necessary to type the main function in certain kinds of C). There are no arguments to this particular program. Inside the braces the program simply spits out "Hello world!". Simple, huh? Here's another:

                  for (i = 1; i <= 20; i++)
                  {
                  printf ("Hello world!\n");
                  }

                  That looks complex, right? It's really not. The grammar of C tells us that the structure we are looking at is a "for loop" (for is a reserved word to indicate for loops). The for loop has no type, but it does have three parameters. Each of those parameters can be as much or as little as you like, but the most basic sort of for loop is for counting, and is pretty straightforward. This particular for loop prints "Hello world!" 20 times.

                  Are you with us so far? Lemme know.
                  The Internet - where men are men, women are men, and teenage girls are FBI agents!

                  I'm the least you could do
                  If only life were as easy as you
                  I'm the least you could do, oh yeah
                  If only life were as easy as you
                  I would still get screwed

                  Comment


                  • #10
                    I'm having problems with line 20 on this...anyone want to help?

                    PHP Code:
                    //__________________________________________________________________________
                    // On my honor...
                    // I have not copied this program code from others or from published sources.
                    // The code for this assignment is original and was created by me.
                    //__________________________________________________________________________


                    #include <stdio.h>
                    main()
                    {
                         
                    // Declare values of the different currencies
                     
                         
                    float a 0.79821// Euro
                         
                    float b 1.00500// Bahamian Dollar 
                         
                    float c 64.00000// Jamacian Dollar
                         
                    float d 1.41603// New Zealand Dollar
                         
                    float e 1.30719// Australian Dollar
                         
                    float dollarAmount 0// US Dollar input
                         
                    float result 0// Currency conversion

                     
                     // List how much each currency is equal to US dollar
                         
                         
                    printf("\n$1 is currently %f Euro"a);
                        
                    printf("\n$1 is currently %f Bahamian Dollar"b);
                         
                    printf("\n$1 is currently %f Jamacian Dollar"c);
                         
                    printf("\n$1 is currently %f New Zealand Dollar"d);
                         
                    printf("\n$1 is currently %f Australian Dollar\n"e);
                     
                     
                    // Conversion from US Dollars to other currencies
                     
                     // This section prompts for how many US Dollars you want to convert
                     
                         
                    printf("\nEnter the dollar amount you want to convert: ");
                        
                    scanf("%f", &dollarAmount);
                     
                     
                    // Conversion from US Dollars to Euro
                     
                         
                    result dollarAmount a;
                         
                    printf("\nThat dollar amount is %.2f Euro"result);
                     
                     
                    // Conversion from US Dollars to Bahamian Dollar
                     
                         
                    result dollarAmount b;
                         
                    printf("\nThat dollar amount is %.2f Bahamian Dollar"result);
                     
                     
                    // Conversion from US Dollars to Jamacian Dollar
                     
                         
                    result dollarAmount c;
                        
                    printf("\nThat dollar amount is %.2f Jamacian Dollar"result);
                     
                     
                    // Conversion from US Dollars to New Zealand Dollar
                     
                         
                    result dollarAmount d;
                        
                    printf("\nThat dollar amount is %.2f New Zealand Dollar"result);
                     
                     
                    // Conversion from US Dollars to Australian Dollar
                     
                         
                    result dollarAmount e;
                            
                    printf("\nThat dollar amount is %.2f Australian Dollar\n"result);
                            
                            
                    getchar();

                    Last edited by GT98; 4 September 2005, 14:47.
                    Why is it called tourist season, if we can't shoot at them?

                    Comment


                    • #11
                      Originally posted by GT98
                      I'm having problems with line 20 on this...anyone want to help?
                      You neither numbered them nor used a proportional font. Which one is line 20?
                      The Internet - where men are men, women are men, and teenage girls are FBI agents!

                      I'm the least you could do
                      If only life were as easy as you
                      I'm the least you could do, oh yeah
                      If only life were as easy as you
                      I would still get screwed

                      Comment


                      • #12
                        What problems, and as Gurm asked, which is line 20 (for your compiler)?

                        - Steve

                        (oh - and it is a proportional font, but it should be monospace )

                        Comment


                        • #13
                          Oops that was a copy and paste from my Mercial C compiler.

                          The first error I get is this:

                          float dollarAmount = 0; // US Dollar input
                          Why is it called tourist season, if we can't shoot at them?

                          Comment


                          • #14
                            try: float dollarAmount = 0.0;

                            I would also suggest to rename your variables to some usefull names e.g. float fltEuroConv = 0.79821; instead of float a = 0.79821; it will make your program more readably.
                            Last edited by KeiFront; 4 September 2005, 13:19.
                            Main: Dual Xeon LV2.4Ghz@3.1Ghz | 3X21" | NVidia 6800 | 2Gb DDR | SCSI
                            Second: Dual PIII 1GHz | 21" Monitor | G200MMS + Quadro 2 Pro | 512MB ECC SDRAM | SCSI
                            Third: Apple G4 450Mhz | 21" Monitor | Radeon 8500 | 1,5Gb SDRAM | SCSI

                            Comment


                            • #15
                              Bah, assembly language for obscure CPUs beats those new fangled languages like "C" any day!

                              Code:
                              ::
                                CK1NOLASTWD ( Check for one argument and clear last command )
                                CK&DISPATCH0 real ( Check for a real on the stack )
                                  ::
                                    %># ( Convert real to hex string )
                                    NULL$ ( Place an empty string on the stack )
                                    #270 THIRTYTWO #* FOUR #/ SWAPDROP ( Calculate size of array in nibbles )
                                    EXPAND ( Expand empty string to calculated size )
                                    
                              CODE
                              	GOSBVL	=SAVPTR	Save RPL registers
                              	D1=D1+	5	D1 -> data stack+1
                              	A=DAT1	A	A -> hxs prolog
                              	D0=A		D0 -> hxs prolog
                              	D0=D0+	10	D0 -> hxs body
                              	P=	7	Set word width to 32 bits
                              	C=DAT0	WP	C = hxs body	
                              	D1=D1-	5	D1 -> data stack
                              	A=DAT1	A	A -> string prolog
                              	D1=A
                              	D1=D1+	10	D1 -> string body
                              	DAT1=C	WP	Write hxs data into string
                              	P=	0	Set reference nibble to zero
                              	LC(5)	#270
                              	B=C	A	B = 624
                              	C=0	W	Clear C
                              	LC(1)	1	C = 1
                              	LAHEX	6C078965
                              	R0=A		R0 = 1812433253
                              	P=	7	Set word size to 32 bits
                              	AD1EX
                              	D1=A		D1 -> mt
                              	D0=A
                              	D0=D0-	8	D0 -> mt-1
                              while	?B>C	A	While C < 624
                              	GOYES	begin	
                              	GOTO	endwhile
                              begin	D0=D0+	8
                              	D1=D1+	8	Increment D0,D1
                              	R3=C	A	R3 = counter
                              	C=DAT0	WP	C = mt-1
                              	R2=C		R2 = mt-1
                              	CSR	WP
                              	CSR	WP
                              	CSR	WP
                              	CSR	WP
                              	CSR	WP
                              	CSR	WP
                              	CSR	WP
                              	CSRB	WP
                              	CSRB	WP	Shift C right 30 bits
                              	A=R2		A = mt-1
                              	A=A!C	WP	A = mt-1 OR (mt-1 sr 30)
                              	AR2EX		A = mt-1, R2 = above
                              	A=A&C	WP	A = mt-1 AND (mt-1 sr 30)
                              	C=R2		C = mt-1 OR (mt-1 sr 30)
                              	C=C-A	WP	C = mt-1 XOR (mt-1 sr 30)
                              	A=R0		A = multiplier
                              	GOSBVL	=MPY	A,C = A*C
                              	C=DAT1	WP	C = mt
                              	A=A+C	WP	A = A+mt
                              	DAT1=A	WP	Write A to string
                              	C=R3		C = counter
                              	C=C+1	A	Increment counter
                              	GOTO	while
                              endwhile	P=	0
                              	GOSBVL	=GETPTR	Restore RPL registers
                              	LOOP		Return to RPL loop
                              ENDCODE
                                  SWAP DROP
                                ; 
                              ;

                              Comment

                              Working...
                              X