1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: #include C++ question

  1. Feb 21, 2010 #1
    #include <iostream>

    #include <iostream>
    #include <string>


    using namespace std;

    struct ElementType
    {
    string Element;
    int AtomicNumber;
    float AtomicMass;
    float Density;

    };
    int main()
    {


    ElementType element1, element2;

    element1.Element = "Boron";
    element1.AtomicNumber = 5;
    element1.AtomicMass = 10.811;
    element1.Density = 2.34;

    cout << "Name = " << element1.Element << endl;
    cout << "Atomic Number = " << element1.AtomicNumber << endl;
    cout << "Atomic Mass = " << element1.AtomicMass << endl;
    cout << "Density = " << element1.Density << endl;


    element2.Element = "Tungsten";
    element2.AtomicNumber = 74;
    element2.AtomicMass = 183.85;
    element2.Density = 19.30;

    cout << "Name = " << element2.Element << endl;
    cout << "Atomic Number = " << element2.AtomicNumber << endl;
    cout << "Atomic Mass = " << element2.AtomicMass << endl;
    cout << "Density = " << element2.Density << endl;
    }
    return 0;
    }

    I just want to display element1 contents

    element1.Element = "Boron";
    element1.AtomicNumber = 5;
    element1.AtomicMass = 10.811;
    element1.Density = 2.34;

    cout << "Name = " << element1.Element << endl;
    cout << "Atomic Number = " << element1.AtomicNumber << endl;
    cout << "Atomic Mass = " << element1.AtomicMass << endl;
    cout << "Density = " << element1.Density << endl;


    arsenal44 is online now Add to arsenal44's Reputation Report Post Reply With Quote
     
  2. jcsd
  3. Feb 21, 2010 #2

    berkeman

    User Avatar

    Staff: Mentor

    Re: C++

    Well, how do you display information from a C++ program?
     
  4. Feb 21, 2010 #3

    Mark44

    Staff: Mentor

    Re: C++

    Isn't the information for element1 and element2 being displayed in main()? I don't understand what the problem is.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook