?
Solved

Variables

Posted on 1998-05-11
12
Medium Priority
?
159 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:flfmdll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 7

Expert Comment

by:faster
ID: 1828404
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
 

Author Comment

by:flfmdll
ID: 1828405
I agree that 1 or 2 seem like good methods Where can I find an example to 'modify' and play around with?
0
 
LVL 7

Expert Comment

by:faster
ID: 1828406
most of such cgi are written in perl.  but using c++ is also quite easy.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 84

Expert Comment

by:ozo
ID: 1828407
I'd generally prefer the 1st method, since users seldom configure their browsers to reject hidden fields.
0
 
LVL 1

Expert Comment

by:Topace
ID: 1828408
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
 

Author Comment

by:flfmdll
ID: 1828409
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
 
LVL 1

Expert Comment

by:Topace
ID: 1828410
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
 
LVL 1

Expert Comment

by:Topace
ID: 1828411
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
 

Author Comment

by:flfmdll
ID: 1828412
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
 
LVL 1

Expert Comment

by:Topace
ID: 1828413
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
 
LVL 1

Accepted Solution

by:
Topace earned 150 total points
ID: 1828414
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
 

Author Comment

by:flfmdll
ID: 1828415
Got it. Thanks.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question