View Full Version : How do I set variables?
plutoniumman
02-09-2004, 08:12 PM
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!
Jason
02-09-2004, 08:50 PM
int c;
for vars to be set in C they need to be declared at the begining of the method or main functions...
Jason
plutoniumman
02-09-2004, 10:59 PM
umm.... ok.
do you know how to do this in C:
<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?
printf("words are in here")
Jason
02-09-2004, 11:49 PM
var TEST = prompt ("Type some thing","")
TEST2=10
if (TEST2 == "10" || TEST == "20"){
document.write("Hello")
} else {
document.write("hi")
}
#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
plutoniumman
02-10-2004, 04:52 AM
the code doesnt prompt me to set the variable TEST.
Thank you for your help!
shmoove
02-10-2004, 11:02 AM
You have to use printf to print the prompt, and then scanf to get the value:
#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
Jason
02-10-2004, 10:06 PM
#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
plutoniumman
02-11-2004, 04:46 PM
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.
plutoniumman
02-11-2004, 04:51 PM
The code Jason has posted gets some where!
I will take it apart and see how He did it.:D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.