...

View Full Version : Need some help for a quiz program



Striker83
06-08-2009, 03:54 PM
Hi,

I'm trying to get a quiz to work but I'm needing some help. Does anyone know any code that has a if, for loop and an array in it and streams questions from a txt file?

Deacon Frost
06-08-2009, 06:05 PM
Hi,

I'm trying to get a quiz to work but I'm needing some help. Does anyone know any code that has a if, for loop and an array in it and streams questions from a txt file?

I think... every language that can be classed as its own programming language can do that O.o.


Do you have any other specifications? Do you want it online? Do you want a program to run? Do you want it to work on the moon?

if 1 = yes
php

if 2 = yes
c++

if 3 = yes
scheme

Gox
06-08-2009, 09:10 PM
From the way the problem is stated this sounds like a homework assignment to me. In which case you (Striker83) should post the code that you have now, and specify the exact problems you're having so that the members here can help you better.

BrickInTheWall
06-09-2009, 09:40 AM
post what you've already figured out and it will be easier for us to help improve etc....
streaming questions from a text file could be achieved relatively easily using the getline() method if you're using C++.

Striker83
06-09-2009, 04:15 PM
Sorry for not being exact guys.

It has to be in C#.

Here's what I've got so far.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;



namespace Quiz2
{
class Program
{
public static string[,] QuestionArray = new string[5, 10];
public string QuestionText;
public string[] Choices;
public int Answer;

static void Main(string[] args)
{
int correct = 0;
using (StreamReader sr = new StreamReader("questions.txt"))
{
while (!sr.EndOfStream)
{
Console.Clear();
for (int i = 0; i < 5; i++)
{
String line = sr.ReadLine();
if (i > 0)
{
if (line.Substring(0, 1) == "#") correct = i;
Console.WriteLine("{0}: {1}", i, line);
}
else
{
Console.WriteLine(line);
}
static void ShowScore()
{
int Counter;

for (Counter = 0; Counter < 5; Counter++)
{ Console.WriteLine(""); }
Console.WriteLine(" " + PlayersName.ToUpper());
Console.WriteLine("");
Console.WriteLine(" You scored " + theScore + " out of 5.");
Console.WriteLine("");
Exit();
}

{
int Counter1, Counter2, AnswerNumber;
char Choice;
string Temp = "";
string CorrectAnswer = "";

AnswerNumber = QuestionNumber + 1;
Choice = 'a';

for (Counter1 = 0; Counter1 < 3; Counter1++)
{ Console.WriteLine(""); }
Console.WriteLine(" QUIZ");
Console.WriteLine("");
Console.WriteLine(" " + AnswerNumber + ". " + QuestionArray[QuestionNumber, 0]);
Console.WriteLine("");
for (Counter1 = 1; Counter1 < 9; Counter1 = Counter1 + 2)
{
if (QuestionArray[QuestionNumber, Counter1][0] == '#')
{
switch (Counter1)
{
case 1: CorrectAnswer = "a"; break;
case 3: CorrectAnswer = "b"; break;
case 5: CorrectAnswer = "c"; break;
case 7: CorrectAnswer = "d"; break;
}
for (Counter2 = 1; Counter2 < QuestionArray[QuestionNumber, Counter1].Length; Counter2++) // Remove # and display rest of answer
Temp = Temp + QuestionArray[QuestionNumber, Counter1][Counter2];
Console.WriteLine(" " + Choice + ". " + Temp);
}
else
{
Console.WriteLine(" " + Choice + ". " + QuestionArray[QuestionNumber, Counter1]);
}
Choice++;
}

for (; ; )
{
Console.Write("Select Answer: ");
ConsoleKeyInfo cki = Console.ReadKey();
if (cki.KeyChar.ToString() == correct.ToString())
{
Console.WriteLine(" - Correct!");
Console.WriteLine("Press any key for next question...");
Console.ReadKey();
break;
}
else
{
Console.WriteLine(" - Try again!");
}
}
}
}
}

}
}
}
}


I'm sure there's a lot wrong but I only started C# last week.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum