generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: c++ beginner challenge #2

Previous Thread :: Next Thread 
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
25 Aug 2012 04:29 PM
make a calculator that can take input like:
input: "1 + 1"
output: "1 + 1 = 2"
input: "4 * 4"
output: "4 * 4 = 16"

the shortest code gets 1k Robuxs
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
25 Aug 2012 04:30 PM
Not the shortest, but just for fun:
http://wiki.roblox.com/index.php/User:XLEGOx/luatext-astexample
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
25 Aug 2012 04:30 PM
I think the prize should be Half Life 3.
Report Abuse
TheMyrco is not online. TheMyrco
Joined: 13 Aug 2011
Total Posts: 15105
25 Aug 2012 04:34 PM
@stravant: "Demonstrates building of a simple AST"

Yeah right.
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
25 Aug 2012 04:36 PM
this for c++, not rbx.lua. but i respect you, so its okay

how much does Half life 3 cost? i have a decent amount of money in my bank account
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
25 Aug 2012 04:38 PM

int main(void) {
int x;
int y;
char op;
std::cin >> x >> op >> y;
int result;
switch (op) {
case '+':
result = x + y;
break;
case '-':
result = x - y;
break;
case '*':
result = x * y;
break;
case '/':
result = x / y;
break;
}
std::cout << x << ' ' << op << ' ' << y << " = " << result;
}

untested
Report Abuse
TheMyrco is not online. TheMyrco
Joined: 13 Aug 2011
Total Posts: 15105
25 Aug 2012 04:40 PM
Myrkos, why not directly print from the case instead?
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
25 Aug 2012 04:42 PM
because would add more lines and it's not needed

myrkos, that's the exact same way I coded it
Report Abuse
TheMyrco is not online. TheMyrco
Joined: 13 Aug 2011
Total Posts: 15105
25 Aug 2012 04:44 PM
@l3: No I don't think that you know what I mean =3
Report Abuse
TheMyrco is not online. TheMyrco
Joined: 13 Aug 2011
Total Posts: 15105
25 Aug 2012 04:47 PM
int main(void)
{
int x, y;
char op;
std::cin >> x >> op >> y;
switch (op)
{
case '+':
std::cout << x << ' ' << op << ' ' << y << " = " << x + y;
break;
case '-':
std::cout << x << ' ' << op << ' ' << y << " = " << x - y;
break;
case '*':
std::cout << x << ' ' << op << ' ' << y << " = " << x * y;
break;
case '/':
std::cout << x << ' ' << op << ' ' << y << " = " << x / y;
break;
}
}
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
25 Aug 2012 04:47 PM
int main(void) {
       int ans, a, b;
       char op;
       std::cin >> a >> op >> b;
       switch(op) {
               case('+'): ans = a + b; break;
               case('-'): ans = a - b; break;
               case('*'): ans = a * b; break;
               case('/'): ans = a / b; break;
       }
       std::cout << a << ' ' << op << ' ' << b << " = " << ans;
       return 0;
}
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
25 Aug 2012 04:49 PM
oh that probably would have been smarter. :)
just so I don't feel bad, well also take character count into affect when finding the winner
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
25 Aug 2012 04:54 PM
Well, I was overthinking this. I was about to use regex .... ew.
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
25 Aug 2012 04:56 PM
yeah a lot of people do. so, did you ever finish that one yesterday?
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
25 Aug 2012 05:00 PM
next challenge is going to involve string manipulation.
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
25 Aug 2012 05:03 PM
I don't have time at the moment, I'm working on a game.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
25 Aug 2012 05:07 PM
>Myrkos, why not directly print from the case instead?

because code repetition is evil :O
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
25 Aug 2012 05:09 PM
what should the next beginner challenge be? rot13 encoding? brainf interpreter?
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
25 Aug 2012 05:22 PM
hmm whatever you want idk
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
25 Aug 2012 05:27 PM
Anyone else have anything to say?
Report Abuse
enumeration is not online. enumeration
Joined: 17 Dec 2011
Total Posts: 2552
25 Aug 2012 05:57 PM
pastebin/jJ5RsVa0

What do I win? :)
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
25 Aug 2012 06:01 PM
@enum

A BRAND NEW SMARTCAR
Report Abuse
TheMyrco is not online. TheMyrco
Joined: 13 Aug 2011
Total Posts: 15105
25 Aug 2012 06:08 PM
>>Myrkos, why not directly print from the case instead?

>because code repetition is evil :O

But you repeated result = hax =3
Report Abuse
L3GabeL4 is not online. L3GabeL4
Joined: 18 Feb 2012
Total Posts: 808
25 Aug 2012 06:11 PM
enumeration is winning.

the prize is a game or 1k robuxs
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
25 Aug 2012 06:14 PM
int main(void) {
std::string expression;
std::getline(std::cin,expression);
std::string command = "echo $((" + expression + "))";
FILE * file = popen(command.c_str(),"r");
char result[5];
fgets(result,4,file);
pclose(file);
std::cout << expression << " = " << result;
}

my solution is cooler
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image