Web Analytics Made Easy -
StatCounter How do I set variables? - CodingForum

Announcement

Collapse
No announcement yet.

How do I set variables?

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

  • How do I set variables?

    Hello, I have been trying to set variables for a long time and I can't figer it out!
    So If you know how to set variables in C, PLEASE POST IT HERE!

  • #2
    int c;


    for vars to be set in C they need to be declared at the begining of the method or main functions...


    Jason

    Comment


    • #3
      umm.... ok.
      do you know how to do this in C:
      Code:
      <script>
      <!--
      var TEST = prompt ("Type some thing","")
      TEST2=10
      if (TEST2 == "10" || TEST == "20"){
      document.write("Hello")
      } else {
      document.write("hi")
      }
      //-->
      </script>
      Can you do this in C?
      My book leaves out brackets in there syntax so I get a lot of errors when I try stuff.

      This is how you display words right?
      Code:
      printf("words are in here")

      Comment


      • #4
        var TEST = prompt ("Type some thing","")
        TEST2=10
        if (TEST2 == "10" || TEST == "20"){
        document.write("Hello")
        } else {
        document.write("hi")
        }


        PHP Code:
        #include <stdio.h>

        int main () {
        char TEST [20]= "type something";
        int TEST2 10;

        if ( 
        TEST2 == 10 || TEST2 == 20 ){
            
        printf("%s","Hello");
        }
        else {
            
        printf("%s","hi");
        }

        return 
        0;


        Jason

        Comment


        • #5
          the code doesnt prompt me to set the variable TEST.
          Thank you for your help!

          Comment


          • #6
            You have to use printf to print the prompt, and then scanf to get the value:
            Code:
            #include <stdio.h>
            
            int main () {
              char text[20];
              printf("Enter a string:\n");
              scanf("%s",text);
              printf("You entered : %s.\n",text);
              return 0;
            }
            shmoove

            Comment


            • #7
              PHP Code:
              #include <stdio.h>



              int main () {

              char TEST [20];

              int TEST2 10;

                 
              //shmooves coded added here....
                
              printf("Type Something\n");
                
              scanf("%s",TEST);
                
              printf("You entered : %s.\n"TEST);

              if ( 
              TEST2 == 10 || TEST == "20" ){

                  
              printf("%s","Hello");

              }

              else {

                  
              printf("%s","hi");

              }



              return 
              0;




              Next time try some code yourself, this was fairly simplistic...

              Jason

              Comment


              • #8
                I have three compilers, Bloodshed, HAM, and one from Barland.
                HAM has some sample code, I have been trying to chang it the way I want it for about a 5 months and nothing happins.

                Thank you for your help, I'm just going to get all the books on C at the library I can find.

                Comment


                • #9
                  The code Jason has posted gets some where!
                  I will take it apart and see how He did it.

                  Comment

                  Working...
                  X