473,396 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Error C2664, C2228

I'm trying to learn how to set ranges by using classes and I get Error c2664 and C2228 when I build. I saw the question in my practice texrbook and I cant figure out what I'm missing.

It says "ui" should have a class on the left of "ui' but it already does.

Its declared right after the Range. Can you help
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cctype>
  5. using namespace std;
  6.  
  7. class IntRange
  8. {
  9. private:
  10.     int input;
  11.     int lower;
  12.     int upper;
  13. public:
  14.     IntRange(int, int);
  15.     int    getInt();
  16. };
  17. IntRange::IntRange(int lower, int upper)
  18. {
  19.     lower = 50;
  20.     upper = 70;
  21. }
  22.  
  23. int IntRange::getInt()
  24. {
  25.     cin.get(input);
  26.     cin.ignore();
  27.  
  28.     while (input < lower || input > upper)
  29.     {    cout <<" The input number is out of range.\n";
  30.         cout <<" Please enter a value between " << lower;
  31.         cout <<" and " << upper << ".\n";
  32.         cin.get(input);
  33.         cin.ignore();
  34.     }
  35.     return input;
  36. }
  37. int main()
  38. {
  39.  
  40.     IntRange Range(55, 65);
  41.     int ui;
  42.  
  43.     cout << "Enter a number between 55 and 65.\n\n";
  44.     cout << "57 is an exit number, entering 57 would stop the program.\n\n";
  45.     ui = Range.getInt();
  46.     while (ui != 57)
  47.     {
  48.         cout <<"You entered " << ui << endl.
  49.         ui = Range.getInt();
  50.     }
  51.     return 0;
  52. }
Mar 18 '07 #1
5 1962
arne
315 Expert 100+
I'm trying to learn how to set ranges by using classes and I get Error c2664 and C2228 when I build. I saw the question in my practice texrbook and I cant figure out what I'm missing.

It says "ui" should have a class on the left of "ui' but it already does.

Its declared right after the Range. Can you help

#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;

class IntRange
{
private:
int input;
int lower;
int upper;
public:
IntRange(int, int);
int getInt();
};
IntRange::IntRange(int lower, int upper)
{
lower = 50;
upper = 70;
}

int IntRange::getInt()
{
cin.get(input);
cin.ignore();

while (input < lower || input > upper)
{ cout <<" The input number is out of range.\n";
cout <<" Please enter a value between " << lower;
cout <<" and " << upper << ".\n";
cin.get(input);
cin.ignore();
}
return input;
}
int main()
{

IntRange Range(55, 65);
int ui;

cout << "Enter a number between 55 and 65.\n\n";
cout << "57 is an exit number, entering 57 would stop the program.\n\n";
ui = Range.getInt();
while (ui != 57)
{
cout <<"You entered " << ui << endl.
ui = Range.getInt();
}
return 0;
}
Your line
Expand|Select|Wrap|Line Numbers
  1.                 cout <<"You entered " << ui << endl.
  2.  
should not end with a '.', but with a ';'. Is that the line the compiler complains about?
Mar 18 '07 #2
yeah, u r right but that's for the error c2228 [It should have been a semicolon]

For the error c2664 on line 26 and 33. If I took away the "input" in the cin.get(input), the error would go away but it doesnt yet do what I'd like it to do...
Mar 18 '07 #3
arne
315 Expert 100+
yeah, u r right but that's for the error c2228 [It should have been a semicolon]

For the error c2664 on line 26 and 33. If I took away the "input" in the cin.get(input), the error would go away but it doesnt yet do what I'd like it to do...
What about
Expand|Select|Wrap|Line Numbers
  1. cin >> input;
  2.  
?
Mar 18 '07 #4
What about
Expand|Select|Wrap|Line Numbers
  1. cin >> input;
  2.  
?
I tried that already so it builds but the problem is there is something wrong with the input, it doesn't redisplay the entered number. It just shows a 0 even if the number entered is 58.

Thats why I was thinking it was the way I was reading the input so I tried using cin.get
Mar 18 '07 #5
arne
315 Expert 100+
I tried that already so it builds but the problem is there is something wrong with the input, it doesn't redisplay the entered number. It just shows a 0 even if the number entered is 58.

Thats why I was thinking it was the way I was reading the input so I tried using cin.get
You may change your constructor to
Expand|Select|Wrap|Line Numbers
  1. IntRange::IntRange( int l, int u )
  2. {
  3.     lower = l;
  4.     upper = u;
  5. }
  6.  
and add
Expand|Select|Wrap|Line Numbers
  1.     cout << input << endl;
  2.  
after the cin to echo your input.
Mar 18 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mkarja | last post by:
Hi, I've been struggling with this error for a while and I don't know what's wrong. Any help would be appreciated. Here's code snippets and the error message. ----------------------------...
4
by: Scott Chang | last post by:
Hi all I copied the following VC++ 6.0 code (written by someone in the website) to my VC++ .Net 2002-Windows XP Pro PC ////****Solution 'dyndllclass' (2 projects)***/// ///***dynapp****(1st...
7
by: inkexit | last post by:
I'm getting these two error mesages when I try to compile the below source code: error C2065: 'input_file' : undeclared identifier error C2228: left of '.eof' must have class/struct/union type ...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
9
by: i | last post by:
#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> char ch; int n,m; void main(); char check(int,int,char); void cash(int,int,char); void debit_card(int,int,char);
2
by: cr55 | last post by:
I was wondering if anyone can help me with this programming code as i keep getting errors and am not sure how to fix them. The error code displayed now is error: C2228: left of '.rent' must have...
1
by: misu101 | last post by:
Hi, I have a VS 6 project and I am trying to compile it using VS 2005. My program has the atlbase.h include which seems to trigger the errors. It used to compile OK using VS 6. The include...
2
by: yalbizu | last post by:
#include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_STUDENTS=20; struct studentType { string studentFName; string studentLName;
0
by: FrankCheung | last post by:
I am using VS 2005 c++ ReportViewer to generate a dynamic report with a date filter. The following is the code contained in the form.h: public: void SetReportParameters() { ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.