The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 9:29 am



 [ 26 posts ]  Go to page Previous  1, 2
More C++ help 
Author Message
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
Depends on what you want displayed.

Everything thing in Java is basically a class. All provided by the Java library so you don't have to implement them yourselves.

_________________
Image


Sat Nov 28, 2009 4:33 pm

Joined: Wed Oct 21, 2009 4:23 pm
Posts: 107
Gender: Male
I know, I know, Java mostly relies on classes. Although, some classes I find are a bit glitchy. When I was first testing Java, I created a Button, and tried to change its size and location, but somehow it just didn't work. The button just filled the empty space of the JFrame, making one huge a** button.


Sat Nov 28, 2009 6:14 pm
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
That's because you didn't specify the size and location when you called the constructor.

_________________
Image


Sun Nov 29, 2009 10:01 am

Joined: Wed Oct 21, 2009 4:23 pm
Posts: 107
Gender: Male
ooo, must've forgotten that then D:


I'll try it again, once I choose to install the Java environment.


Sun Nov 29, 2009 12:49 pm
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
I use NetBeans.

_________________
Image


Mon Nov 30, 2009 7:12 am
User avatar

Joined: Tue Nov 17, 2009 1:26 am
Posts: 648
Gender: Anime Girl
Yes, here I am again. :P

I had a busy time, but now I have some slack and I am trying to write a short quiz. However, I got an error when initialising a multidimensional array.

Code:
int LetterOrder[4][24] = {{1, 2, 3, 4}, {1, 3, 2, 4}, {1, 3, 4, 2},
{1, 2, 4, 3}, {1, 4, 3, 2}, {1, 4, 2, 3}, {2, 1, 3, 4}, {2, 3, 1, 4},
{2, 3, 4, 1}, {2, 1, 4, 3}, {2, 4, 3, 1}, {2, 4, 1, 3}, {3, 2, 1, 4},
{3, 1, 2, 4}, {3, 1, 4, 2}, {3, 2, 4, 1}, {3, 4, 1, 2}, {3, 4, 2, 1},
{4, 2, 3, 1}, {4, 3, 2, 1}, {4, 3, 1, 2}, {4, 2, 1, 3}, {4, 1, 3, 2},
{4, 1, 2, 3}};


I use the header files <iostream> and <cstring>.

Then I get the following error:
Code:
too many initializers for `int[4][24]'


I use Dev-C++ as an editor and a compiler.

Edit: Nevermind, I got it fixed. I still errors when running it, though.

_________________
Image
Liberal Socialist Mudraking Bastard (Averted, not performing any journalism)


Thu Dec 17, 2009 1:54 pm
User avatar

Joined: Tue Nov 17, 2009 1:26 am
Posts: 648
Gender: Anime Girl
It compiles now, but is fails when running.

This is the program:

Code:
#include <iostream>
#include <cstring>
using namespace std;

int RandomNumber (int Divide) {
   static long r = 42;
   r = ((929 * r / 5 - 7) * 41) / Divide;
   return r;
} // RandomNumber

int main ( ) {
   int NumberOfQuestions = 5, Requested, QuestionNumber, Order, Score;
   int a, b, c, d;
   char Answer;
   string Questions[5] = { -questions- };
   string Answers[5][4] = {{ -answers- }};
   int LetterOrder[24][4] = {{0, 1, 2, 3}, {0, 2, 1, 3}, {0, 2, 3, 1},
   {0, 1, 3, 2}, {0, 3, 2, 1}, {0, 3, 1, 2}, {1, 0, 2, 3}, {1, 2, 0, 3},
   {1, 2, 3, 0}, {1, 0, 3, 2}, {1, 3, 2, 0}, {1, 3, 0, 2}, {2, 1, 0, 3},
   {2, 0, 1, 3}, {2, 0, 3, 1}, {2, 1, 3, 0}, {2, 3, 0, 1}, {2, 3, 1, 0},
   {3, 1, 3, 0}, {3, 2, 1, 0}, {3, 2, 0, 1}, {3, 1, 0, 4}, {3, 0, 2, 1},
   {3, 0, 1, 2}};
   cout << "How many questions do you want?\n"
        << "(Currently there are only five questions, so you are likely to get some multiple times if you want more than two questions)\n" << endl;
   cin >> Requested;
   while (Requested != 0) {
      QuestionNumber = RandomNumber (NumberOfQuestions);
      Order = RandomNumber (24);
      a = LetterOrder[Order][0], b = LetterOrder[Order][1], c = LetterOrder[Order][2];
      d = LetterOrder[Order][3];
      cout << Questions[QuestionNumber] << endl
           << "A: " << Answers[QuestionNumber][a] << endl
           << "B: " << Answers[QuestionNumber][b] << endl
           << "C: " << Answers[QuestionNumber][c] << endl
           << "D: " << Answers[QuestionNumber][d] << endl;
      cin >> Answer;
      if (((Answer < 'a') && (Answer > 'd')) || ((Answer < 'A') && (Answer > 'D'))) {
         cout << "Get your eyes fixed, goofball!" << endl;
         return 1;
      } // if
      if ((Answer < 'a') && (Answer > 'd'))   
         Answer = Answer + 'A' - 'a';
      Answer = Answer - 'a';
      if (LetterOrder[Order][Answer] == 0) {
         cout << "You got the right answer!\n" << endl;
         Score++;
      } // if
      else
         cout << "Sorry, you got it wrong.\n" << endl;
      cout << "Score: " << Score << endl << endl;
      Requested--;
   } // while
   cout << "Well, that's it! Bye!" << endl;
   system("PAUSE");
   return 0;
} // main


It fails after the first cout.

Does anybody know what I'm doing wrong?

_________________
Image
Liberal Socialist Mudraking Bastard (Averted, not performing any journalism)


Wed Dec 23, 2009 3:09 pm
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
What was the exact run time error?

Also isn't there PRNG built in to C?

_________________
Image


Wed Dec 23, 2009 11:51 pm
User avatar

Joined: Tue Nov 17, 2009 1:26 am
Posts: 648
Gender: Anime Girl
I got no exact error, all it did was ceasing to function.

I thought there was, but I heard it was only randm to a limited degree in the sense you would have to recompile it in order to change the random number.

_________________
Image
Liberal Socialist Mudraking Bastard (Averted, not performing any journalism)


Thu Dec 24, 2009 4:26 am
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
Villerar wrote:
I got no exact error, all it did was ceasing to function.

I thought there was, but I heard it was only randm to a limited degree in the sense you would have to recompile it in order to change the random number.

Does C++ come with a Random object? It should have a function to keep generating random numbers within your constraints when a specific method in it is called. Prolly called next() or something. In any case, I really can't help you much more. I have trouble trying to make it work on Visual C# and I'm too lazy to rewrite it.

_________________
Image


Thu Dec 24, 2009 4:57 am
User avatar

Joined: Tue Nov 17, 2009 1:26 am
Posts: 648
Gender: Anime Girl
I think it is a segmentation fault, by the way. I also think I found the problem.

_________________
Image
Liberal Socialist Mudraking Bastard (Averted, not performing any journalism)


Sat Dec 26, 2009 10:47 am
Display posts from previous:  Sort by  
 [ 26 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users and 1 guest


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
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.