Jump to content

Welcome to 1Emulation.com
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account
Photo

C class is opening.

- - - - -

  • Please log in to reply
23 replies to this topic

#12
someboddy

someboddy

    Sergeant Moderator

  • Ultra Members
  • 1,657 posts
  • Gender:Male
  • Location:The Israeli Army
Click to view battle stats

To hell with that! hahaha... too much for my brain! How about this:
10 print 10*10
run
100
end

There you have the program. command to run it. and the output...... granted, it won't be the next Quake Engine but hey.... hahaha

10 print"End of TapeWurm's Stupid Message"
run
End of TapeWurm's Stupid Message
End of TapeWurm's Stupid Message
End of TapeWurm's Stupid Message
End of TapeWurm's Stupid Message
End of TapeWurm's Stupid Message
End of TapeWurm's Stupid Message
End of TapeWurm's Stupid Message
End of TapeWurm's Stupid Message


What softwere did you use?
tapeworm++?
visual tapeworm?

#13
someboddy

someboddy

    Sergeant Moderator

  • Ultra Members
  • 1,657 posts
  • Gender:Male
  • Location:The Israeli Army
Click to view battle stats
type this program:

#include <stdio.h>

void main(){
int num;
printf("ngive me a number ");
scanf("%d",&num);
if (num>0){
 printf("your number is positiven");
}
if (num<0){
 printf("your number is negativen");
}
if (num==0){  
 printf("your number is zeron");
}  
}


and now I will explain:

from now on I will explain only the new commands.

if (num>0){
this is a "if" command. when the programs reach to a if command, it only does the commands between the "{" and "}", if the term between the baraks is true. that mean, that only if "num>0" when the program reach to the if command, it will do the commands between the "{}" ("printf("your number is positiven");
")

A if command may have anuther part: the "else" part.
if (<term>){
<code1>
}
else{
<code2>
}


if <term> is true, do <code1>, else do <code2>.

#14
ken_cinder

ken_cinder

    Cyborg Admin

  • User Admin
  • 4,484 posts
  • Gender:Male
  • Location:Inside my PC
  • Interests:Everything
Click to view battle stats

What softwere did you use?
tapeworm++?
visual tapeworm?

No that wold be good ol BASIC.

Thanks for the quick insight on some short programs in C++
I've been looking for an excuse to crack open my Viz studio 6 CD's, and something simple like this may just gimme a bit more of a push.

:)

#15
someboddy

someboddy

    Sergeant Moderator

  • Ultra Members
  • 1,657 posts
  • Gender:Male
  • Location:The Israeli Army
Click to view battle stats
type this program:

#include <stdio.h>

void main(){
int x,sum;
printf("ngive me numbersn");
sum=0;
x=1;
while (x!=0){
 scanf("%d",&x);
 sum=sum+x;
}
printf("Your numbrs total is %d.n",sum);
}


the new command is while loop.

this is how the wile loop works:

[I]while (<term>){
<code>
}

when the program is getting to a while loop, it checks <term>, if <term> is true, the program do <code>, else, it continus the code after the loop.
when the program end's <code>, it's check <term> again, if <term> is true, the program do <code>, else, it continus the code after the loop.

while loop are good when you dont know how many times the loop shold be, and you dont have this information on a variable.

#16
someboddy

someboddy

    Sergeant Moderator

  • Ultra Members
  • 1,657 posts
  • Gender:Male
  • Location:The Israeli Army
Click to view battle stats
Type this program:

#include<stdio.h>

void main(){
int a[5],b[5],c[5],i;
for (i=0;i<5;i++){
 printf("ngive me two numbers('a,b') ");
 scanf("%d,%d",&a,&b);
 c=a+b;
}
for (i=0;i<5;i++){
 printf("n %d+%d=%d",a,b,c[i]);
}
printf("nnn");
}


there are parts here that I have allrady explaind, so I only explain the new thing: the array.

array is a set of variables that have serial numbers. when you want to use one of the variables in the array, you use it like this: [I]<array name>[<variable serial number>]
. for example: [i]bla[5]
,[i]x[7]
,[i]set[9].

array is defined like a normal variable, only that a array have a "["&"]" around the number of variables. for example:
[i]int thing[3];
defines a array with a place for 3 integer variables.

the serial number of the first variable in the array is 0. for example:if we have a array: [i]staff[6], then the variables are: 'staff[0]','staff[1]','staff[2]','staff[3]','staff[4]' and 'staff[5]'.

instend of puting a number inside the "["&"]", you can put an integer in it, like [i]something[i]. this makes arrays extreamly useful in for loops.

#17
someboddy

someboddy

    Sergeant Moderator

  • Ultra Members
  • 1,657 posts
  • Gender:Male
  • Location:The Israeli Army
Click to view battle stats
this time I have two simple programs:

#include <stdio.h>

void main(){
float a,b,c;
printf("nnGive me two numbers ");
scanf("%f,%f",&a,&:(:;
c=a+b;
printf("n %f+%f=%fnn",a,b,c);
}


this is a simple adding program, but it have diferent from the program in the second lesson: it uses real numbers, that mean that we can do 4.79+5.3, for example.
using real numbers it's vwry similar to using integers but when you defining the variable, write "float " instend of "int ", and when using it in a "printf""scanf", write "%f" instend of "%d".

and one more thing: you cant put a real number in a integer.

#18
someboddy

someboddy

    Sergeant Moderator

  • Ultra Members
  • 1,657 posts
  • Gender:Male
  • Location:The Israeli Army
Click to view battle stats
type this program:

#include <stdio.h>

void main(){
char anser;
printf("nnDo you like me?(y/n) ");
scanf ("%c",&anser);
if (anser=='y') printf("nI like you toonn");
if (anser=='n') printf("nThis means war!!!nn");
}


the char is a single character variable.

#19
someboddy

someboddy

    Sergeant Moderator

  • Ultra Members
  • 1,657 posts
  • Gender:Male
  • Location:The Israeli Army
Click to view battle stats
type this program:

#include<stdio.h>
void main(){
char name[100];
printf("nnWhat's your name? ");
scanf("%s",&name);
printf("Hello %snn",name);
}


when you make an array of char's, you can use it as a string, but instend of typing "%c", type "%s".

#20
someboddy

someboddy

    Sergeant Moderator

  • Ultra Members
  • 1,657 posts
  • Gender:Male
  • Location:The Israeli Army
Click to view battle stats
These are the basic of c, and as soon as I whill learn C++, I whill teach you that too.

#21
emsley

emsley

    Emsley here. That's right.

  • 1Emu Veteran
  • 6,772 posts
  • Gender:Male
  • Location:England.
  • Interests:Yelling.
Click to view battle stats
Just one question?
What the hell would it do if i learned it?
People who talk programing are crazy :( 8)

#22
someboddy

someboddy

    Sergeant Moderator

  • Ultra Members
  • 1,657 posts
  • Gender:Male
  • Location:The Israeli Army
Click to view battle stats
You will be able to create programs and games.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users