viet_mafia 0 Newbie Poster

Thanks for the tips Matt, however I'm restricted to using only XHTML so I don't really have a choice. I wrote up another script but when i click on calculate it does nothing and just shows theres an error on the page. Could anyone help please?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head><title>BMI Calculator</title>

<script type="text/javascript">
<!-- Hide script from non-script-friendly browsers
function BMI_Calculator()
{
	n = prompt('What is your age?',"");

	if (n <= 17)
	   { document.write("We are unable to calculate your BMI"); }
	else if(n => 18)
	   { h = prompt('What is your height in metres?',"");
	     w = prompt('What is your weight in kilograms?',"");
	     bmi = Math.round(w / (h*h));

	     switch(bmi)
		{
			case bmi <= 19: 
				message = "Underweight";
				break;
			case bmi >= 20 && bmi <= 25:
				message = "Acceptable";
				break;
			case bmi >= 26 && bmi <=30:
				message = "Overweight";
				break;
			case bmi >= 31:
				message = "Obese";
				break;
			default: message = "Error!";
				break;
		}

	comment = "<html><head><title>Your BMI</title></head><body>" + 
		   "<h1>BODY MASS INDEX (BMI) CALCULATOR</h1><p>Your height = " + 
		   h + "<br>Your weight = " + w + "<br>Your BMI = " + bmi + "</p><p>" + 
		   "<h2>what your BMI Indicates</h2><br>" + message + "</p>";

	document.write (comment);

}
// stop hiding the script-->
</script>
</head>

<body>

<a href="javascript: BMI_Calculator()">Calculate</a>

</body>
</html>
viet_mafia 0 Newbie Poster

Hey guys, i followed your suggestions but it still doesnt work for me. I don't get any prompts or anything. I've done the right thing and saved it as javascript.js haven't I? or should i save it as something else? thanks for the help so far.

What i have so far:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head><title>BMI Calculator</title>

<script type="text/javascript">
<!-- Hide script from non-script-friendly browsers
function BMI Calculator(bmi)
{
var bmi = w / (h*h);
return bmi;
}
//stop hiding the script-->
</script>

<script type="text/javascript">
<!-- Hide script from non-script-friendly browsers
var n;
var a;
var h;
var w;
var bmi;
n = prompt("What is your age? ","");
if (n <= 17)
{
document.write("We are unable to calculate your BMI");
}
else if(n => 18)
{
h = prompt("What is your height in metres?","");
w = prompt("What is your weight in kilograms?","");
bmi = w / (h*h);

if (bmi <= 19)
{ 
message = "Underweight"; 
}
else if (bmi >= 20 && bmi <= 25)
{ 
message = "Acceptable"; 
}
else if (bmi >= 26 && bmi <=30)
{ 
message = "Overweight"; 
}
else if (bmi >= 31)
{ 
message = "Obese"; 
}
else
{ 
message = "Error!"; 
}
}
// stop hiding the script-->
</script>
</head>

<body>

comment= ("<html><head><title>Your BMI</title></head><body><h1>BODY MASS INDEX (BMI) CALCULATOR</h1>
<p>Your height= " + h + "<br>Your weight= " + w + "<br>Your BMI= " + …
viet_mafia 0 Newbie Poster

Hi everyone, I'm pretty new to Javascript and I guess I'm pretty nooby at it so I have a problem with some Javascript I'm trying to write. Basically I'm creating some Javascript that will allow me to calculate someone's Body Mass Index (BMI) and so far with my code have absolutely no idea what's wrong with it. If you guys could lead me in the right direction it would be much appreciated :cheesy:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head><title>BMI Calculator</title>

 <script type="javascript">
 <!-- Hide script from non-script-friendly browsers
  function BMI Calculator(bmi)
  {
    var bmi = w / (h*h);
    return bmi;
  }
 //stop hiding the script-->
 </script>
</head>

<body>
<script type="javascript">
    <!-- Hide script from non-script-friendly browsers
    var n;
    var a;
    var h;
    var w;
    var bmi;
    n = prompt("What is your age? ","");
    if (n <= 17)
    {
    document.write("We are unable to calculate your BMI");
    }
    else if(age => 18)
    {
    h = prompt("What is your height in metres?","");
    w = prompt("What is your weight in kilograms?","");
    bmi = w / (h*h);

    if (bmi <= 19)
    { 
    message = "Underweight"; 
    }
    else if (bmi >= 20 && bmi <= 25)
    { 
    message = "Acceptable"; 
    }
    else if (bmi >= 26 && <=30)
    { 
    message = "Overweight"; 
    }
    else if (bmi >= 31)
    { 
    message = "Obese"; 
    }
    else
    { 
    message = "Error!"; 
    }

    content = ("<html><head><title>Your BMI</title></head><body><h1>BODY MASS INDEX (BMI) CALCULATOR</h1>
    <p>Your height= " + …
viet_mafia 0 Newbie Poster

Hi guy, I need to create a program that sorts 3 words entered into order from shortest to longest. So far I have the following done but when I run it, it only displays the first two words in order of length and doesnt show the 3rd word. Can anyone tell me what is wrong with it?

#include<iostream>
#include<string>

using namespace std;
int main()
{
    int num1,num2,num3,ntemp, count = 0;
    string name1,name2,name3,stemp;
    
    cout << "enter 3 words.\n";
    cin >> name1 >> name2 >> name3;
    num1 = name1.length();
    num2 = name2.length();
    num3 = name3.length();
    
    while (count <= 1)
    {
    if (num1 > num2)
    {
             num1 = ntemp;
             num1 = num2;
             num2 = ntemp;
             
             name1 = stemp;
             name1 = name2;
             name2 = stemp;
    }
    
    if ( num2 > num3 )
    {
             num2 = ntemp;
             num2 = num3;
             num3 = ntemp;
             
             name2 = stemp;
             name2 = name3;
             name3 = stemp;
    }
     
    count++;
    }   
    cout << name1 << " " << name2 << " " << name3 << " ";
    
    system("pause");
    return 0;
}
viet_mafia 0 Newbie Poster
#include <iostream>
using namespace std;
int main()
{
    const int MAXNUMS = 5;
    int count;
    int num, total;

cout << "\nThis program will ask you to enter " << MAXNUMS << " numbers.\n";
count = 1;
total = 0;
    while (count <= MAXNUMS)
    {
        cout << "Please input integer " << count << " : "; 
        cin >> num;
        if ( num % 2 == 0 )// % is the Modulus, it gives the remainder after dividing by 2.
        {
              total = total + num ;    
        }
    count++;
}
    cout << "Even Number Total is " << total << endl ;   
             
    system("pause");
    return 0;
}

this should help you out, only calculates the even numbers out of 5 inputs, displaying the total of the even numbers at the end.

you can thank me later :mrgreen:

viet_mafia 0 Newbie Poster
#include <iostream>
#include <string.h>
using namespace std;
int main ()
{
int ref,x,y,z;
char word1[50] = "word1 string";
char word2[50] = "word2 string";
char word3[50] = "word3 string";
string wordsml;
string wordmed;
string wordlge;
cout<<"This program will ask you to enter 3 words. \n"
"It will then diplay them in order of word length \n"
"(Shortest word first)"<<endl;

cout<<"\tPlease enter 3 words\n";
cin>>word1>>word2>>word3;
x=strlen (word1);
y=strlen (word2);
z=strlen (word2);
if (x<y)
{
wordsml = word1;
wordlge = word2;
}
if (x>y)
{
wordsml =word2;
wordlge = word1;
}
ref=strlen(wordlge.c_str());
if (ref<z)
{
wordmed = wordlge;
wordlge = word3;
}
if (ref>z);
wordmed = word3;
cout<<"The order of words from smallest to largest is "<<wordsml<<" and "<<wordlge<<" and "<<wordmed<<endl;
system("pause");
return 0;
}

that should be the end to your problems.

edit: OK guess not :o