[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Variables

Posted on 1998-05-11
12
Medium Priority
?
160 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
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

650 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