-
February 24th, 2009, 10:48 AM
#1
little help
How can i initialize a variable called get_info?
Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct Rectangle
{
double width;
double length;
};
void get_info (Rectangle &abcd);
{
cout<<"Enter the length: ";
cin>>abcd.length;
cout<<"Enter the width: ";
cin>>abcd.width;
}
int main()
{
Rectangle get_info;
cout<<"The area of the rectangle is: "<< get_info.length*get_info.width;
return 0;
}
-
February 24th, 2009, 10:59 AM
#2
Re: little help
I suggest giving the Rectangle object a better name than get_info, especially since get_info is already a name of a function. If you really insist on the conflicting and rather misleading name, then you have to qualify the name of the function as being in the global namespace, e.g.,
Code:
Rectangle get_info;
::get_info(get_info);
cout<<"The area of the rectangle is: "<< get_info.length*get_info.width;
By the way, it looks like you have a stray semi-colon at the end of this line:
Code:
void get_info (Rectangle &abcd);
-
February 24th, 2009, 11:02 AM
#3
Re: little help
Originally Posted by igodspeed
How can i initialize a variable called get_info?
Write a constructor for it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|