raider650

[CODE]

include
include
include

using namespace std;

// Arrays......
int i(0);
double Calc(double fahren);
double Total(0),Celsius[5],Fahrenheit[5];
double CelsiusLowTemperature(0), FahrenheitLowTemperature(1000),
CelsiusHighTemperature(0),
FahrenheitHighTemperature(-1000);
double Mean_Celsius, Mean_Fahrenheit, ;
string Command;

struct WeatherStation {

string StationName;

double Temperature;

};

WeatherStation PostTemperatures()
{
WeatherStation Values;
WeatherStation Names;

cout<< "\n"<< "Enter reported temperatures..."<<"\n"<< "\n";

Names.StationName = "Big Basin";
cout <<  "Weather Station " << Names.StationName<<"  : ";
cin >> Values.Temperature;

Names.StationName = "Foothill";
cout <<  "Weather Station " << Names.StationName<<"  : ";
cin >> Values.Temperature;

Names.StationName = "DeAnza";
cout <<  "Weather Station " << Names.StationName<<"  : ";
cin >> Values.Temperature;

Names.StationName = "MiddleField";
cout <<  "Weather Station " << Names.StationName<<"  : ";
cin >> Values.Temperature;

Names.StationName = "Redwood City";
cout <<  "Weather Station " << Names.StationName<<"  : ";
cin >> Values.Temperature;

return Values;
return Names;

}

void displayData(string str, double val1, double val2) // function
{
cout.precision(3);
cout<<str<<val1<<" "<<val2<<endl;
cout<<" ---------------------------------------------------"<<endl;
}

void ListMenu() // Displays Weather Report Menu
{

cout<<"Command Choices................"<<"\n"<<endl;
cout<<"_____________________________"<<"\n"<<endl;
cout<<"\t"<<"Post Temperatures" <<"\n"<<endl;
cout<<"\t"<<"Daily Report" <<"\n"<<endl;
cout<<"\t"<<"High-Low Report" <<"\n" <<endl;
cout<<"\t"<<"Quit" <<"\n"<<endl;
cout<<"_____________________________"<<"\n"<<endl;

}

void DailyReport() // Outputs Daily Report
{
cout.precision(3);
cout<<" ========NGS Daily Temperature Data Report======== "<<endl;
cout<<" Fahrenheit Celsius "<<endl;
//cout<< PostTemperatures()<<endl;
cout<<" --------------------------------------------------------------"<<endl;
displayData("Mean Temperature: ", Mean_Fahrenheit , Mean_Celsius);
cout<<"\n";
}

void HighLowReport() // Outputs High-Low Report
{
cout<<" ========NGS Temperature Data Report======== "<<endl;
cout<<" Fahrenheit Celsius "<<endl;
displayData("Lowest Temperature: ", FahrenheitLowTemperature, CelsiusLowTemperature);
displayData("Highest Temperature: ", FahrenheitHighTemperature, CelsiusHighTemperature);
cout<<" =============End Temperature Data Report============="<<endl;
}

double Calc(double fahren) // Function, Converts Fahrenheit to Celsius...
{
double cel;
cel = (5 ...

raider650

Here is part of the code:

[CODE]

include
include
include

using namespace std;

// Arrays......
int i(0);
double Calc(double fahren);
double Total(0),Celsius[5],Fahrenheit[5];
double CelsiusLowTemperature(0), FahrenheitLowTemperature(1000),
CelsiusHighTemperature(0),
FahrenheitHighTemperature(-1000);
double Mean_Celsius, Mean_Fahrenheit ;
string Command;

struct WeatherStation {

string StationName;

double Temperature;

};

void PostTemperatures(WeatherStation BigBasin,WeatherStation Foothill,WeatherStation DeAnza,
WeatherStation MiddleField,WeatherStation RedwoodCity)
{

cout<< "Enter reported temperatures..."<<"\n"<< "\n";

BigBasin;
BigBasin.StationName = "Big Basin";
cout << "Weather Station " << BigBasin.StationName<<" : ";
cin >> BigBasin.Temperature;

Foothill;
Foothill.StationName = "Foothill";
cout << "Weather Station " << Foothill.StationName<<" : ";
cin >> Foothill.Temperature;

DeAnza;
DeAnza.StationName = "DeAnza";
cout << "Weather Station " << DeAnza.StationName<<" : ";
cin >> DeAnza.Temperature;

MiddleField;
MiddleField.StationName = "MiddleField";
cout << "Weather Station " << MiddleField.StationName<<" : ";
cin >> MiddleField.Temperature;

RedwoodCity;
RedwoodCity.StationName = "Redwood City";
cout << "Weather Station " << RedwoodCity.StationName<<" : ";
cin >> RedwoodCity.Temperature;

}

void ListMenu() // Displays Weather Report Menu
{

cout<<"Command Choices................"<<"\n"<<endl;
cout<<"_____________________________"<<"\n"<<endl;
cout<<"\t"<<"Post Temperatures" <<"\n"<<endl;
cout<<"\t"<<"Daily Report" <<"\n"<<endl;
cout<<"\t"<<"High-Low Report" <<"\n" <<endl;
cout<<"\t"<<"Quit" <<"\n"<<endl;
cout<<"_____________________________"<<"\n"<<endl;
//cout<<"Enter Command : "<<endl;

}

void displayData(string str, double val1, double val2) // function
{
cout.precision(3);
cout<<str<<val1<<" "<<val2<<endl;
cout<<" ---------------------------------------------------"<<endl;
}

double Calc(double fahren) // Function, Converts Fahrenheit to Celsius...
{
double cel;
cel = (5 *(fahren - 32))/9.0;
return cel;

}

int main()
{

while(true)  

{
ListMenu();
cout << "Enter Command: ";
getline(cin, Command);

    if(Command == "Quit")
        break;
    else if(Command == "Post Temperatures")
        PostTemperatures(); // Here is where the error occurs
    else if(Command == "Daily Report")
        break;
    else if(Command == "High-Low Report")
        break;

}

}

[/CODE]

raider650

In other words, how do I call void PostTemperatures?

Ive tried:

PostTemperatures();

But it gives me an error.

"error: at this point in file"

raider650 Newbie Poster

How would I output this into:

int main()

I've tried:
int main()
{
PostTemperatures;
}

[CODE]struct WeatherStation {

string StationName;

double Temperature;

};

void PostTemperatures(WeatherStation BigBasin,WeatherStation Foothill,
WeatherStation DeAnza, WeatherStation MiddleField,
WeatherStation RedwoodCity)
{
cout<< "Enter reported temperatures..."<<"\n"<< "\n";

BigBasin;
BigBasin.StationName = "Big Basin";
cout <<  "Weather Station " << BigBasin.StationName<<"  : ";
cin >> BigBasin.Temperature;

Foothill;
Foothill.StationName = "Foothill";
cout <<  "Weather Station " << Foothill.StationName<<"  : ";
cin >> Foothill.Temperature;

DeAnza;
DeAnza.StationName = "DeAnza";
cout <<  "Weather Station " << DeAnza.StationName<<"  : ";
cin >> DeAnza.Temperature;

MiddleField;
MiddleField.StationName = "MiddleField";
cout <<  "Weather Station " << MiddleField.StationName<<"  : ";
cin >> MiddleField.Temperature;

RedwoodCity;
RedwoodCity.StationName = "Redwood City";
cout <<  "Weather Station " << RedwoodCity.StationName<<"  : ";
cin >> RedwoodCity.Temperature;

}

[/CODE]

raider650

Sound about right. But how would I go by implementing the new data structure into the program?

Sorry I'm very new to this so excuse any questions that might seem obvious.

-- Thanks.

raider650 Newbie Poster

[B]I included my original code down below....Basically I need some input on where to start off. From what I can tell it seems that I will need to re-organize the code into functions, while implementing the new data structure. Any input would be greatly appreciated.[/B]

This time the program would be written using functions instead of putting all the code in main(). You need to rewrite the software from Lab 02 so that it effects these changes.

New data structure to represent the information that comes from each weather station:

struct WeatherStation {

        string StationDesignation;

        double Temperature;

};

Your new program will need to store this information in an array of WeatherStation objects, and you will have to supply functions to allow the user to

post the temperatures that come in from the various weather stations

display the temperatures in both fahrenheit and celsius for each weather station

calculate and display the highest temperature as well as the lowest among the five stations.

In addition, you need to design and implement a reasonable user interface (NOT A GUI!). Study the sample screens below to gain insight into what the program is expected to do...

Choices...................

    Post Temperatures

    Daily Report

    High-Low Report

    Quit

Enter Command:

Choices...................

    Post Temperatures

    Daily Report

    High-Low Report

    Quit

Enter Command: Post Temperatures

Enter reported temperatures...

Weather Station Big Basin: 55

Weather Station Foothill: 56

Weather Station DeAnza: 55

Weather Station MiddleField: 44

Weather Station Redwood City: 57

Enter Command: Daily ...

raider650 Newbie Poster

Everything runs fine, except the Lowest Temperature and HIghest Temperature do not output correctly.
Also any suggestions on how I could implement vectors,

Any help would be greatly appreciated.

Thanks.

[CODE]

include

using namespace std;

int main()
{
int i(0);
double Calc(double fahren);
double Total(0),Celsius[5],Fahrenheit[5];
double CelciusLowTemp(0), FahrenheitLowTemp(0), CelciusHighTemp(0), FahrenheitHighTemp(0);
double Mean_Celcius, Mean_Fahrenheit;

cout<< "Enter reported temperatures..."<<"\n"<< "\n";

for(i=0;i<5;i++) //Loops

{
cout<<"Weather Station "<<i<<" = ";// Takes input for Reported Temperatures...
cin>>Fahrenheit[i];

    if (FahrenheitLowTemp < 0.1)               //Conditionals
        FahrenheitLowTemp = Fahrenheit[i];
    else (FahrenheitLowTemp > Fahrenheit[i]);

FahrenheitLowTemp = Fahrenheit[i];

    if (FahrenheitHighTemp < 0.1)
        FahrenheitHighTemp = Fahrenheit[i];
    else (FahrenheitHighTemp < Fahrenheit[i]);

FahrenheitHighTemp = Fahrenheit[i];

Celsius[i] = Calc(Fahrenheit[i]);

Total+=Fahrenheit[i];

}
CelciusLowTemp = Calc(FahrenheitLowTemp);
CelciusHighTemp = Calc(FahrenheitHighTemp);
Mean_Fahrenheit = Total/5.0;
Mean_Celcius = Calc(Mean_Fahrenheit);
cout<<" ========NGS Temperature Data Report======== "<<endl;
cout<<" Fahrenheit Celsius "<<endl;
cout<<" --------------------------------------------------------------"<<endl;
cout<<"Lowest Temperature: "<<FahrenheitLowTemp<<" "<<CelciusLowTemp<<endl;
cout<<" --------------------------------------------------------------"<<endl;
cout<<"Highest Temperature: "<<FahrenheitHighTemp<<" "<<CelciusHighTemp<<endl;
cout<<" --------------------------------------------------------------"<<endl;
cout<<"Mean Temperature: "<< Mean_Fahrenheit<<" "<<Mean_Celcius<<endl;
cout<<" --------------------------------------------------------------"<<endl;
cout<<"Raw Data..."<<endl;
cout<<"\n";

    for(i=0;i<5;i++) {

cout<<"WeatherStation "<<i<<":          "<<Fahrenheit[i]<<"          "<<Celsius[i]<<endl;

}
cout<<" --------------------------------------------------------------"<<endl;
cout<<" =============End Temperature Data Report============="<<endl;

}

double Calc(double fah)

{
double cel;
cel = (5 *(fah - 32))/9.0;
return cel;

}

[/CODE]

raider650 Newbie Poster

BMI= w/(h/100)2

[CODE]double BMI = weight/(height*height)// Works when weight=kilograms, height= meters [/CODE]
I need the output to be in kilograms and centimeters.

Any help, much appreciated.

raider650

[QUOTE=raider650;1006989]

61.23497 kg = weight
165.1 cm = height

Made a couple of changes...

So after getting rid of the "DecimalFormat" from the program( the output was way off), I was finally able to get the BMI output somewhat accurate; 0.0022464. It should actually read 22.464.[/QUOTE]

Sorry I found the problem. The formula for Computing BMI using centimeters is; w
BMI = ___
(h/100) 2

Question; How do I add an exponent in java?? Or how do I add an exponent to the end of ; BMI = weight/(height/100)

[CODE]double BMI = weight/(height/100);[/CODE]

Thanks in advance.

raider650

I switched the weight and height to integers(Int) and now it won't calculate the users BMI properly.

What am I doing wrong?

Everything looks about right, not sure why it doesn't work. Any help, much appreciated.

raider650

[code]

import javax.swing.*;
//import java.text.DecimalFormat;

public class Main {

public static void main(String args[ ]) {
int weight = (int) .453592; // converts to kg
int height = (int) 2.54; // converts to centimeters

 weight = (int)Double.parseDouble(JOptionPane.showInputDialog(null,"Enter your weight in kilograms"));

 height = (int)Double.parseDouble(JOptionPane.showInputDialog(null,"Enter your height in centimeters"));

 double BMI = weight/(height*height);

// DecimalFormat fmt = new DecimalFormat("#.##");

 JOptionPane.showMessageDialog(null, "Your Body Mass Index is: " + BMI + ".");

}

}

[/code]

61.23497 kg = weight
165.1 cm = height

Made a couple of changes...

So after getting rid of the "DecimalFormat" from the program( the output was way off), I was finally able to get the BMI output somewhat accurate; 0.0022464. It should actually read 22.464.

raider650 Newbie Poster

Basically I need to write an application to calculate BMI using the formula;

BMI = w/ (h/100) 2

The user must type in her height in centimeters and weight in kilograms, and the computer prints out the user's BMI.

import java.util.Scanner;
import java.text.DecimalFormat;

public class BMI {

public static void main(String args[ ]){

double pound = .453592;
double inches = 2.54;

Scanner scan = new Scanner(System.in);

System.out.println("Enter in your weight: ");
double weight = scan.nextDouble();

System.out.println("Enter in your height: " );
double height = scan.nextDouble();

weight = weight * pound ;// Converts pounds to kilograms
height = height * inches ;// Converts inches to centimeters

double BMI = weight/(height*height);// Computes users BMI

DecimalFormat fmt = new DecimalFormat("0.00");// Rounds answer to 2 decimal places.

System.out.println("Your Body Mass Index is: " + fmt.format(BMI));

I keep getting "Your BMI is: 0". What am I doing wrong? Any suggestions, thanks in advance.

Also I'll be using JOptionPane.showInputDialog() to get user input and JOptionPane.showMessageDialog() to print the results to the user.