i have this given structure:

struct Tempscale
{
	double farenheit; 
	double centigrade;
};

struct Reading
{
	int windSpeed;
	double humidity;
	Tempscale temperature;
};

i am then asked:
define a Reading structure variable
is this ok: Reading data;
write statements that will display following data:
wind speed : 37mph
humidity: 32%
farenheit temperature: 32 degrees
centigrade temperature: 0 degrees

my question:
can i use a declaration and cout statement for the data?
ex:

data.windspeed = 37;
data.humidity = 32;

cout << data.windspeed << "mph" << endl;
cout << data.humidity<< "%" << endl;

i think this is the correct way to write the statement for the first 2, but how do i write a statement that will store the data for the farenehit and centigrade? (since temperature is a TempScale structure variable)

the second part of the question asks me to write a function called findReading that should use Reading structure variable as its parameter. the function should then ask user to enter values for each member of the structure

Recommended Answers

All 3 Replies

>>but how do i write a statement that will store the data for the farenehit and centigrade?

Here is how to access farenheight -- you should be able to figure out the other yourself. data.temperature.farenheit = 32; As for the second part -- do you know how to write a function? And how to use cin and cout ?

im iffy on using functions and structures together-so to answer ur question: not really. no :(

All it wants you to do is create a function named findReading with one parameter, which is a reference to a Reading structure.

void findReading( Reading & rd)
{
   // put your code here.  use cout to display prompts and cin to get keyboard input.
}


// here is how to call the above function
int main()
{
    Reading rd;
    findReading(rd);

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.