Home Forums Gamescan Chat42 About
* Login   * Register * FAQ    * Search
It is currently Sat 11-15-2025 4:32PM

All times are UTC - 6 hours




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: C++ question
PostPosted: Wed 01-26-2005 9:10PM 
Offline
Brigadier General
User avatar

Joined: Mon 08-16-2004 10:40AM
Posts: 1460
Location: \/ I hate these guys /\ (Altman 209)

Source: Altman Hall
Im new to C++ and Ive got a question, I dont know how to do it in C++, but how do i create a "sub" or "marker" that i can send the program to if certain things are true or input, such as


Quote:
person puts in a 1 for H


if H=1 goto "sub" something
else goto "sub" somethingelse


sub something

code
code
code
code
code

sub somethingelse

code
code
code
code
code





I used the sub command when messing with Easy UO scripting but apparently its not the same in C++, is there a command like this or am I just having wishful thinking? I cant seem to find anything like it in the book and would appreciate any light that someone could shed on the situation... I know I dont have all the correct symbols in there but thats the basic idea of what I'm trying to do...

_________________
"Nuke 'em till they glow, then shoot 'em in the dark!"


Top
 Profile  
    
 Post subject:
PostPosted: Wed 01-26-2005 9:20PM 
Offline
Colonel
User avatar

Joined: Sun 08-18-2002 10:33AM
Posts: 751
Location: Kansas City, KS

Source: TJ North
Functions? They don't have to take arguments or return anything:

Code:
void something() {
  // code goes here
}

void somethingelse() {
  // more code
}

void main() {
  int h = 1;
  if(h == 1) something();
  else something();
  // more code after something() or somethingelse() returns
}

_________________
It is by caffeine alone I set my mind in motion.
It is by the beans of Java the thoughts acquire speed,
the hands acquire shaking, the shaking becomes a warning.
It is by caffeine alone I set my mind in motion.


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Wed 01-26-2005 9:26PM 
Offline
Brigadier General
User avatar

Joined: Mon 08-16-2004 10:40AM
Posts: 1460
Location: \/ I hate these guys /\ (Altman 209)

Source: Altman Hall
hmm thatll work for what I'm looking for, but is there a way to make it move to that part of the program and continue on instead of going to that function, doing it, then going back to the point it came from?

_________________
"Nuke 'em till they glow, then shoot 'em in the dark!"


Top
 Profile  
    
 Post subject:
PostPosted: Wed 01-26-2005 11:13PM 
Offline
Major General
User avatar

Joined: Wed 08-25-2004 8:55PM
Posts: 2969

Source: TJ South
not that i know of.

you can put whatever code you want inside the fucntion to make it seem like its continuing on, but the way c++ works is to call a function to do something then return to the main function


Top
 Profile  
    
 Post subject:
PostPosted: Wed 01-26-2005 11:21PM 
Offline
Captain

Joined: Mon 01-12-2004 2:59PM
Posts: 109

Source: TJ North
Code:
#include <iostream>

int main()
{
    std::cout << "1 or 2: ";

    int num; std::cin >> num;

    if (num == 1)
        goto one;
    else
        goto two;

    one:
    std::cout << "you typed one";

    goto exit;

    two:
    std::cout << "you typed two";

    exit:

    return 0;
}


edit; reason u wont find it in a book is because its LAME


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 01-27-2005 12:39AM 
Offline
Captain
User avatar

Joined: Thu 08-28-2003 9:50AM
Posts: 100

Source: TJ South
devil, shut up. you are useless. take your former roommate's dick out of your mouth and go eat a new dick, dickeater.

_________________
"That which does not kill us, only makes us stronger."

"Why did the dinosaurs die?" - Peter Griffin
"Because you touch yourself at night."- Museum Curator


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 01-27-2005 12:45AM 
Offline
Penis Hater
User avatar

Joined: Mon 02-16-2004 1:47PM
Posts: 2106

Source: Fidelity
Code:
int main()
{
   if(h == 1)
   {
      do something;
   }
   else
   {
      do something else;
   }
   code after something and something else;
}


Same as using functions that genpfault showed. Do NOT use gotos.

_________________
My girlfriend went to London and all I got was this lousy sig.

My new title was my idea...


Top
 Profile  
    
 Post subject:
PostPosted: Thu 01-27-2005 1:51AM 
Offline
Brigadier General
User avatar

Joined: Mon 08-16-2004 10:40AM
Posts: 1460
Location: \/ I hate these guys /\ (Altman 209)

Source: Altman Hall
thanks for the help guys, appreciate it!

_________________
"Nuke 'em till they glow, then shoot 'em in the dark!"


Top
 Profile  
    
 Post subject:
PostPosted: Thu 01-27-2005 6:13PM 
Offline
Brigadier General
User avatar

Joined: Mon 08-16-2004 10:40AM
Posts: 1460
Location: \/ I hate these guys /\ (Altman 209)

Source: Altman Hall
i got another one, i cant get my if-else statement to output a message

Quote:
if (t==H)
cout << "Enter age (in calender years)\n";
else if (t==D)
cout << "Enter age in Human years: \n";


i need it to output one of these statements depending on what the user inputs for t, and then i need to request a particular input depending also on what t==, but when i have it setup like above it wont display either of the cout statements if an approptiate choice it pushed in, it simply ignores them and goes on

_________________
"Nuke 'em till they glow, then shoot 'em in the dark!"


Top
 Profile  
    
 Post subject:
PostPosted: Thu 01-27-2005 6:22PM 
Offline
Colonel
User avatar

Joined: Sun 08-18-2002 10:33AM
Posts: 751
Location: Kansas City, KS

Source: TJ North
Can you post the rest of your code? The snippit you gave is rather ambiguous.

_________________
It is by caffeine alone I set my mind in motion.
It is by the beans of Java the thoughts acquire speed,
the hands acquire shaking, the shaking becomes a warning.
It is by caffeine alone I set my mind in motion.


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 01-27-2005 6:32PM 
Offline
Brigadier General
User avatar

Joined: Mon 08-16-2004 10:40AM
Posts: 1460
Location: \/ I hate these guys /\ (Altman 209)

Source: Altman Hall
I'll pm it to you

_________________
"Nuke 'em till they glow, then shoot 'em in the dark!"


Top
 Profile  
    
 Post subject:
PostPosted: Thu 01-27-2005 7:28PM 
Offline
"para-dime"
User avatar

Joined: Tue 09-11-2001 2:34PM
Posts: 1084
Location: Off Campus (i.e. not hell)

Source: VPN
Just by looking at it... if you are expecting the characters 'D' and 'H' you need to put the single quotes around them. If they're actually variables forget what I just said.

_________________
People with doctorate degrees get to be called Doctor. So yes, I guess I am your Master... bitch


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 01-27-2005 8:15PM 
Offline
Brigadier General
User avatar

Joined: Mon 08-16-2004 10:40AM
Posts: 1460
Location: \/ I hate these guys /\ (Altman 209)

Source: Altman Hall
ahh ok, got that fixed, one last question, what do i punch in to make it "clear" everything after the program starts, so it wont have all my other junk above the actual program??

_________________
"Nuke 'em till they glow, then shoot 'em in the dark!"


Top
 Profile  
    
 Post subject:
PostPosted: Thu 01-27-2005 10:07PM 
Offline
Captain

Joined: Mon 01-12-2004 2:59PM
Posts: 109

Source: TJ North
on console?

system("CLS");


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 01-27-2005 11:56PM 
Offline
Brigadier General
User avatar

Joined: Mon 08-16-2004 10:40AM
Posts: 1460
Location: \/ I hate these guys /\ (Altman 209)

Source: Altman Hall
where do i put that? it just brings up errors when i try to put it in...

_________________
"Nuke 'em till they glow, then shoot 'em in the dark!"


Top
 Profile  
    
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group