mwahahaha my first major coding langauge. what shall it be.

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

spylogo
Posts: 43
Joined: Thu Aug 23, 2007 7:32 am UTC

mwahahaha my first major coding langauge. what shall it be.

Postby spylogo » Thu Aug 23, 2007 7:36 am UTC

I chose c++ of all things...................

User avatar
Torn Apart By Dingos
Posts: 817
Joined: Thu Aug 03, 2006 2:27 am UTC

Postby Torn Apart By Dingos » Thu Aug 23, 2007 7:41 am UTC

Great. Start coding.

spylogo
Posts: 43
Joined: Thu Aug 23, 2007 7:32 am UTC

kk

Postby spylogo » Thu Aug 23, 2007 7:47 am UTC

i already started like 2 days ago. been using the internet to learn. so far....... believe it or not i spent half an hour longer cuz i accidentally backspaced a semicolon and didnt notice.

first program to test basic commands. changed it like 10 times...... this is the final product.

#include "stdafx.h"
#include <iostream>

using namespace std;

void main()
{
int x;

x = -10;
while ( x < 1)
{

cout << "Hello World! " << -x << "\n";

x++;
}
system("pause");
}




my second one where i made it execute basic .bat files



#include "stdafx.h"

#include <iostream>

using namespace std;

int main(void)
{
int yes;
int no;
int maybe;
int answer;
yes=1;
no=0;
maybe=2;
cout<<"Welcome To Unbanner!\nType 1 for debanner, 2 for blah, or 0 to quit\n";
system("pause");
cout<<"Type Answer:";cin>> answer;
if (answer==yes) {
cout<<"Please open your web browser and delete your cookies now.\n";
system("pause");
puts("Starting Unban Process....");
spawnl( P_WAIT, "blah.bat",
"blah.bat", "Using spawnl", "Arg1", "Arg2", NULL );
system("pause");
}
if (answer==maybe) {
cout<<"Please wait...\n"; 0.
system("pause");
puts("blah");
spawnl( P_WAIT, "blah1.bat",
"blah1.bat", "Using spawnl", "Arg1", "Arg2", NULL );
system("pause");
}
return 0;
}


so what should i work on now?(i do know its kinda hard to read other peoples scripts but these are pretty simple)

User avatar
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Postby evilbeanfiend » Thu Aug 23, 2007 8:05 am UTC

look at http://projecteuler.net/ maybe?

btw, declaring main to return void and system("pause"); aren't portable, its a good idea to avoid non-portable code in general, although there is obviously no harm here other than getting in to bad habits

also you may want to use the code /code tags and some indentaion to make things read nicer
in ur beanz makin u eveel

spylogo
Posts: 43
Joined: Thu Aug 23, 2007 7:32 am UTC

Postby spylogo » Thu Aug 23, 2007 8:12 am UTC

oh lol i stole system pause from c language. and the void main instead of int main was probably a mistake.

User avatar
shawncplus
Posts: 15
Joined: Wed Aug 01, 2007 3:10 am UTC
Contact:

Postby shawncplus » Thu Aug 23, 2007 1:09 pm UTC

If you are writing in C++ you really shouldn't mix C with C++ (mixing puts
with cout) also the yes no maybe you have could be simplified to an unnamed enum

Code: Select all

enum { YES, NO, MAYBE };

Yes is automatically initialized as 0, No would then be 1, and Maybe 2.

Since you are using iostream system("pause"); can easily be replaced by
cin.get() (sometimes you need to call it twice).


On to ideas:

The most basic thing I can think of that is still somewhat practical is a ROT13 en/decypher. ROT13 is just a caeser cypher meaning the alphabet is shifted by a certain number, in this case, 13.

Since you already know C here is a very small ROT13 program in C, try and convert it over to C++ (it's not really that difficult given the source

Code: Select all

#include <cstdio>
#include <ctype.h>
using namespace std;
int main()
{
    char userInput[512];
    int i;
    printf(">");
    gets(userInput);
    for (i=0;i < sizeof(userInput);i++){   
        userInput[i]=toupper(userInput[i]); 
        if(int(userInput[i])>=65  && int(userInput[i])<=77)
             userInput[i] += 13;
        else if(int(userInput[i])>=78 && int(userInput[i])<=90)
             userInput[i] -= 13;
    }
    for (i=0;i < sizeof(userInput);i++){
        userInput[i]=tolower(userInput[i]);
    }
    printf(">%s", userInput);
    return 0;
}


(it is a command line utility so it doesn't pause)
Excuse me while I gather the virgin sacrifice and assemble the pentagram required to solve your problem.

User avatar
Aglet
Posts: 364
Joined: Tue Mar 13, 2007 12:26 am UTC

Postby Aglet » Thu Aug 23, 2007 6:39 pm UTC

How come you're using stdafx.h in the first one? Is there something I'm missing in it?
Image

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Postby EvanED » Thu Aug 23, 2007 6:59 pm UTC

spylogo wrote:oh lol i stole system pause from c language. and the void main instead of int main was definitely a mistake.


Fixed. ;-)

shawncplus wrote:Since you are using iostream system("pause"); can easily be replaced by cin.get() (sometimes you need to call it twice).


As I mentioned the last time this came up, they do slightly different things. There is no standard C++, portable way to do the same thing as system("pause"). Using cin.get() or cin.ignore() is close, but it's not the same.

And, since portability doesn't rule all, it's quite reasonable to use system("pause") if that isn't a concern for you.

(Note that this is different than the void/int main thing, because there is no reason to declare main as void. Using "int" can save you keystrokes, won't change the behavior (if "void main" even compiles), and doesn't cost anything. If I were an instructor, I would mark down assignments that use void main. Depending on how the course was set up and how the assignments work, I might not mark down those that uses system("pause").)

Aglet wrote:How come you're using stdafx.h in the first one? Is there something I'm missing in it?


That's a Visual Studio, precompiled header thing.

cpedant
Posts: 2
Joined: Thu Aug 23, 2007 11:07 pm UTC

Postby cpedant » Thu Aug 23, 2007 11:30 pm UTC

shawncplus wrote:[...]

Since you already know C here is a very small ROT13 program in C, try and convert it over to C++ (it's not really that difficult given the source

Code: Select all

#include <cstdio>
#include <ctype.h>
using namespace std;
int main()
{
    char userInput[512];
    int i;
    printf(">");
    gets(userInput);
    for (i=0;i < sizeof(userInput);i++){   
        userInput[i]=toupper(userInput[i]); 
        if(int(userInput[i])>=65  && int(userInput[i])<=77)
             userInput[i] += 13;
        else if(int(userInput[i])>=78 && int(userInput[i])<=90)
             userInput[i] -= 13;
    }
    for (i=0;i < sizeof(userInput);i++){
        userInput[i]=tolower(userInput[i]);
    }
    printf(">%s", userInput);
    return 0;
}


(it is a command line utility so it doesn't pause)


This isn't standard C. using namespace std; is a syntax error, among other things.

User avatar
shawncplus
Posts: 15
Joined: Wed Aug 01, 2007 3:10 am UTC
Contact:

Postby shawncplus » Fri Aug 24, 2007 8:09 pm UTC

The only thing that is different is that it should use stdio.h instead of cstdio
and the using namespace I forgot to take out since Dev-C++ automatically
puts the include and that when I make a new file.


Other than that there is no standardization issues, as to the void main
it is completely incorrect because the only thing defined in the ISO C++
standard is int main() and int main(int argc, char *argv[])
Excuse me while I gather the virgin sacrifice and assemble the pentagram required to solve your problem.

User avatar
djn
Posts: 610
Joined: Mon May 07, 2007 1:33 pm UTC
Location: Oslo, Norway

Postby djn » Fri Aug 24, 2007 8:50 pm UTC

I'm fairly sure int() isn't a C function, either. You either want atoi, or just a cast. (In this case, you don't even need to cast.)

I think this is better?

Code: Select all

#include <ctype.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv) {
    char userInput[512];
    int i, length;

    printf(">");
    fgets(userInput, 512, stdin);
    length = strlen(userInput);

    for (i=0; i<length; i++) {
        userInput[i] = tolower(userInput[i]) ;
        if (userInput[i]>='a' && userInput[i]<='m')
             userInput[i]+=13;
        else if(userInput[i]>='n' && userInput[i]<='z')
             userInput[i]-=13;
    }

    printf(">%s", userInput);
    return 0;
}


And, just to verify.

Code: Select all

nord> tcc -Ysystem -Xp xkcd.c
nord> gcc -Wall -ansi xkcd.c
nord> ./a.out
>abcxyz
>nopklm


If anyone wonders, tcc is the TenDRA C compiler, here set to link to system libraries, and in strict ANSI mode with some extra checks. I like to test with it, it's rather picky and has decent error messages.

spylogo
Posts: 43
Joined: Thu Aug 23, 2007 7:32 am UTC

Postby spylogo » Tue Aug 28, 2007 6:14 am UTC

thanks guys. well hopefully my transition wont be too bad from c to c++. this site was helpful though. http://www.cprogramming.com/tutorial/c-vs-c++.html

spylogo
Posts: 43
Joined: Thu Aug 23, 2007 7:32 am UTC

Re: mwahahaha my first major coding langauge. what shall it be.

Postby spylogo » Mon Oct 22, 2007 8:16 pm UTC

well its been about 2 months and well i think i might move on to using Directx. any suggestions?

User avatar
Pathway
Leon Sumbitches...?
Posts: 647
Joined: Sun Oct 15, 2006 5:59 pm UTC

Re: mwahahaha my first major coding langauge. what shall it be.

Postby Pathway » Tue Oct 23, 2007 5:20 am UTC

Try Java.
SargeZT wrote:Oh dear no, I love penguins. They're my favorite animal ever besides cows.

The reason I would kill penguins would be, no one ever, ever fucking kills penguins.

spylogo
Posts: 43
Joined: Thu Aug 23, 2007 7:32 am UTC

Re: mwahahaha my first major coding langauge. what shall it be.

Postby spylogo » Tue Oct 23, 2007 5:33 am UTC

I wanna spend more time on C++ before I move to java if i do.

julesh
Posts: 22
Joined: Wed Jul 04, 2007 9:20 am UTC

Re: mwahahaha my first major coding langauge. what shall it be.

Postby julesh » Tue Oct 23, 2007 5:28 pm UTC

I first tried to learn OOP in C++. I think it was a mistake. I kept trying to figure out how everything worked, and couldn't get my head around multiple inheritance.

Then I switched to Borland Pascal with Objects (essentially an early version of what's now called Delphi). Because it was a simpler system, I could figure it out better, and now I don't care how it works I've gone back to C++.

For somebody moving from C to OOP today, I'd recommend either Delphi, Java or C#. Any of them are great environments to work in, and much easier to understand than C++ is. Then switch back to C++ when you've got the hang of thinking in objects.

Random832
Posts: 2525
Joined: Wed Oct 10, 2007 4:38 pm UTC

Re:

Postby Random832 » Fri Oct 26, 2007 2:36 pm UTC

shawncplus wrote:The only thing that is different is that it should use stdio.h instead of cstdio
and the using namespace I forgot to take out since Dev-C++ automatically
puts the include and that when I make a new file.


Other than that there is no standardization issues, as to the void main
it is completely incorrect because the only thing defined in the ISO C++
standard is int main() and int main(int argc, char *argv[])


Also, C is not defined to use ASCII. Not sure about C++.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests