#include%26lt;iostream%26gt;
#include%26lt;string%26gt;
struct company
{
string str;
int diameter;
double weight;
};
int main ()
{ using namespace std;
company pizza =
{
cout %26lt;%26lt; "Enter the name of the company:" endl;
getline(cin,str);
cout %26lt;%26lt; "Enter the diameter of the pizza: " ;
cin %26gt;%26gt; diameter %26gt;%26gt; endl;
cout %26lt;%26lt; "Enter the weight:";
cin %26gt;%26gt; weight %26gt;%26gt; endl;
return 0;
}
}
This is C++ code it can complie i dont understand the problem?
You said this code compiles? You must have one low quality compiler. No way does this code compile, as you have posted it anyway.
company pizza =
{
cout %26lt;%26lt; "Enter the name of the company:" endl;
getline(cin,str);
cout %26lt;%26lt; "Enter the diameter of the pizza: " ;
cin %26gt;%26gt; diameter %26gt;%26gt; endl;
cout %26lt;%26lt; "Enter the weight:";
cin %26gt;%26gt; weight %26gt;%26gt; endl;
return 0;
}
^^^ this is syntactic nonsense.
Reply:#include%26lt;iostream%26gt;
#include%26lt;string%26gt;
using namespace std;
struct company
{
string str;
int diameter;
double weight;
};
int main ()
{
company pizza;
cout %26lt;%26lt; "Enter the name of the company:" %26lt;%26lt; endl;
getline(cin,pizza.str);
cout %26lt;%26lt; "Enter the diameter of the pizza: " ;
cin %26gt;%26gt; pizza.diameter;
cout %26lt;%26lt; endl;
cout %26lt;%26lt; "Enter the weight:";
cin %26gt;%26gt; pizza.weight;
cout %26lt;%26lt; endl;
return 0;
}
You had a problem with the way that you setup and referenced your struct. I also moved the namespace.
Check out the following for more information: http://www.cprogramming.com/tutorial/les...
chrysanthemum
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment