Post: Magic 8 Ball Program c#
09-07-2015, 05:53 AM #1
HeroWin
Java Developer
(adsbygoogle = window.adsbygoogle || []).push({});
8 BALL Program By HeroWin

You must login or register to view this content.

Picture
You must login or register to view this content.

Source Code
You must login or register to view this content.


You must login or register to view this content.


Made a basic text based question and answer program... with rand number functions

Note: Since this is my first program... the only question you can ask is BASIC questions.
09-07-2015, 01:27 PM #2
vRice
Haxor!
For a first program it's decent, only thing I could suggest is use an array instead of a switch to get your answer Happy
09-07-2015, 03:24 PM #3
Winter
Purple God
Originally posted by HeroWin View Post
8 BALL Program By HeroWin

You must login or register to view this content.

Picture
You must login or register to view this content.

Source Code
You must login or register to view this content.


You must login or register to view this content.


Made a basic text based question and answer program... with rand number functions

Note: Since this is my first program... the only question you can ask is BASIC questions.


Here's what I made in C++ as a little demo

    
#include <iostream>
#include <string>


char* answers[] = {
"Yes",
"No",
"It would be benefical for you",
"Possbily",
"Maybe"
};

int main() {
printf("Magic 8 Ball\n\n");
start:
std::string buf;
std::getline(std::cin, buf);

printf("%s\n", answers[rand() % sizeof(answers)/4]);
goto start;
}

The following user thanked Winter for this useful post:

Chen Madhala
09-07-2015, 03:29 PM #4
Winter
Purple God
And in C# just because why not

    
using System;

namespace Magic_8_Ball {
class Program {

static string[] answers = new string[] {
"Yes",
"No",
"It would be benefical for you",
"Possbily",
"Maybe"
};

static void Main(string[] args) {
Console.WriteLine("Magic 8 Ball\n");
start:
Console.ReadLine();

Console.WriteLine("{0}", answers[new Random().Next(0, answers.Length)]);
goto start;
}
}
}

The following user thanked Winter for this useful post:

Chen Madhala
09-07-2015, 05:59 PM #5
HeroWin
Java Developer
Originally posted by vRice View Post
For a first program it's decent, only thing I could suggest is use an array instead of a switch to get your answer Happy


yeah i heard arrays are useful all around the place... will learn

The following user thanked HeroWin for this useful post:

avatar1o1234
09-08-2015, 02:20 AM #6
Trefad
I defeated!
Originally posted by Winter View Post
And in C# just because why not

    
using System;

namespace Magic_8_Ball {
class Program {

static string[] answers = new string[] {
"Yes",
"No",
"It would be benefical for you",
"Possbily",
"Maybe"
};

static void Main(string[] args) {
Console.WriteLine("Magic 8 Ball\n");
start:
Console.ReadLine();

Console.WriteLine("{0}", answers[new Random().Next(0, answers.Length)]);
goto start;
}
}
}


Damn......
09-08-2015, 02:05 PM #7
Winter
Purple God
Originally posted by Trefad View Post
Damn......


It doesn't get much more barebones than that.. lmao
09-09-2015, 01:19 AM #8
Default Avatar
Oneup
Guest
Originally posted by HeroWin View Post
yeah i heard arrays are useful all around the place... will learn



ArrayLists are pretty nice thing to use as well.

The following user thanked Oneup for this useful post:

Mango_Knife

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo