Variables

Is there a clean way in CGI to present a series of questions that will be 'graded' and a rolling total maintained throughout the questions. The questions might be on a series of pages. I know little to nothing about CGI. I do have appropriate tools for creating HTML and I program in C++ all the time.
flfmdllAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fasterCommented:
There are several ways to do this.

The easiest way is to store the score in a hidden field of the html pages.  For example, suppose you have 3 pages, each containing one question, the first page does not need to contain anything special.  When the user submit the first one, your cgi will check its answer and give it a score, the score should be written to an hidden field in the 2nd page, this means that the 2nd page must be dynamically generated (normally you will use a template html and then the cgi just replace the score), after user submit the 2nd, your cgi need to retrieve the score and then add it with the score for the current page, then generate the 3rd page.

Another way is to use cookie, which means you store the score in a cookie, this is actually quite similar to the 1st solution.

The 3rd way is to store the score in a database (or any storage on the server), this is more complicated, because you of course need to ask the user to logon so that you can store the score along with the user id.

If this score is not something very important, I suggest that you use the 1st or 2nd way.
0
flfmdllAuthor Commented:
I agree that 1 or 2 seem like good methods Where can I find an example to 'modify' and play around with?
0
fasterCommented:
most of such cgi are written in perl.  but using c++ is also quite easy.
0
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

ozoCommented:
I'd generally prefer the 1st method, since users seldom configure their browsers to reject hidden fields.
0
TopaceCommented:
Well, Here is a piece of code I designed.  Feel free to use it if you want.  It is in C++, so it will need to be compiled before it is placed on the net:  (It's also a multiple choice test)

<#include iostream.h>

char answer1;
char answer2;

main();
{
 cout >> "Question 1\n";   // Your first Question
 cout >> "(A) Answer 1\n"; // Possible Answers
 cout >> "(B) Answer 2\n";
 cout >> "(C) Answer 3\n";
 cout >> "(D) Answer 4\n";
 cin << answer1;

 cout >> "Question 2\n";   // Your second Question
 cout >> "(A) Answer 1\n"; // Possible Answers
 cout >> "(B) Answer 2\n";
 cout >> "(C) Answer 3\n";
 cout >> "(D) Answer 4\n";
 cin << answer2;

  if (answer1 = 'a' && answer2 = 'a')
   {
    cout >> "You have recieved an 'A' !\n"
   }
  else if )(answer1 != 'a' && answer2 = 'a')
   {
    cout >> "You have recieved a 'B' !"
   }
  else if (answer1 = 'a' && answer2 != 'a')
   {
    cout >> "You have recieved a 'B' !"
   }
  else
   {
    cout >> "You have failed this test.  Have a nice day."
   }

 return 0;

}


I may have mixed up a few things, as I am a little new to C++, but this seems like it would work.  Tell me if it does.


Topace


0
flfmdllAuthor Commented:
Either my question wasn't worded correctly or I don't understand your answer. These questions span multiple HTML pages. I don't see how your solution would track the score across pages.
0
TopaceCommented:
Hmmm....  If you adapted the code a little so that the forms from each of the pages were put in as variables, then the program could total it throughout the pages.  It wouldn't be hard....Let me think about it.  


Topace
0
TopaceCommented:
Hmmmm...

I have been thinking about this, and there has GOT to be a logical way to do it in Javascript.  However, what I have come up with is that the questions will need to be multiple choice unless you want to have it match against a string that is correct.

Do you want the questions to be multiple choice?


Topace  


0
flfmdllAuthor Commented:
The questions will either be Yes/No or multiple choice. At least there is nothing in the current requirements that suggest a string answer. How much harder will that make it?
0
TopaceCommented:
Here's what I have:

First off, you want javascript on your first HTML page to determine whether or not the answer chosen is correct.  Then, it should run the CGI, if the answer was correct, initilizing a variable to 1, otherwise initializing it to 0.  Then, have the CGI script pass the next HTML page on to the user, setting (If Wanted) a different question depending on whether or not the variable is 1.  Then, just increment the variable every time the client types in a right answer, with each step (Again, If Wanted) creating a new HTML question depending on whether or not the last one was correct.  Then, when you get to the last HTML page, just show them their score (The Orginal Variable) out of how many possible (A constant created with how many points are possible), and then divide the variable by the constant and multiply by 100 into a new variable to show them the percentage.  I would reccommend the last variable (Percentage) be a short unsigned, that way there will be no decimal.  

School is out tomorrow, and I will have time to type up some code illustrating this for you in the form of answer.  

I hope this helped you to understand what I have been trying (Unsuccessfully) to show you what I am going to do.


Topace
0
TopaceCommented:
Okay, here is what I have come up with:

HTML PAGE #1:

<HTML>
<HEAD> yada yada yada...some code...</HEAD>

<BODY BACKGROUND="whatever.gif" TEXT=#whatever>
<CENTER><h1>Question 1</h1></CENTER>
<FORM NAME="theNumberOne" METHOD=POST ACTION="/cgi-bin/thescript.cgi>
<SELECT NAME="answer1">
                          <OPTION> Possible Answer1 </OPTION>
                          <OPTION> Possible Answer2 </OPTION>
                          <OPTION> Possible Answer3 </OPTION>
                          <OPTION> Possible Answer4 </OPTION>
                          </SELECT><br>
<CENTER><INPUT TYPE=SUBMIT VALUE="CHOOSE THIS ANSWER">

</BODY>
</HTML>


Now, HERE is the SCRIPT:

<#include iostream.h>  // For cout ( You can use whatever)
#define Correct_Answer1 something_here
short unsigned int No_Correct = 0;
char *pGrabbed_Answer;
pGrabbbed_Answer = getenv("QUERY_STRING");

 main()
{
 cout >> "Content-Type: text/html\n\n"
 cout >> "<HTML>"

if (pGrabbed_Answer == NULL){
 cout >> "<H1>ERROR: No content was recieved."};

else if (pGrabbed_Answer ==  Correct_Answer1){
 cout >> "<BODY BACKGROUND='whatever' TEXT=#Whatever>"
 cout >> "<CENTER><h1>NEXT QUESTION</h1></CENTER><br>"
 cout >> "<FORM NAME='Question2'><br><SELECT NAME='Answer2'>"
 cout >> "Yada Yada...Next Question CODE"
 No_Correct++;
}

else {

cout >> "<H1> SORRY, YOUR ANSWER WAS INCORRECT.</h1>

 };

}



Hope this helps, if not...I will add more.


Topace

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
flfmdllAuthor Commented:
Got it. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.