473,383 Members | 1,832 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,383 software developers and data experts.

Scope error in C++

The following code throws an error saying 'd' not in scope.

Please help.

Expand|Select|Wrap|Line Numbers
  1. const char* user::getDate(char* d)
  2. {
  3.     return d;
  4. }
  5.  
  6. float user::calculate_interest(int t_accno, float t_balance)
  7. {
  8.   fstream file, file1;
  9.   //float t_interest;
  10.   int dd,mm,yy;
  11.   file.open("bank.dat", ios::binary | ios::in);
  12.   file.open("transaction.dat", ios::binary | ios::in);
  13.   file.seekg(0, ios::beg);
  14.   int d1, m1, y1, days;
  15.   while (file.read((char *)this, sizeof(user)))
  16.   {
  17.     if (accountNo == t_accno)
  18.     {
  19.       d1 = dd;
  20.       m1 = mm;
  21.       y1 = yy;
  22.       break;
  23.     }
  24.   }
  25.   int d2, m2, y2;
  26.   //struct date d;
  27.   //time_t d = time(0);
  28.   getDate(char *d);
  29.   d2 = d.da_day;
  30.   m2 = d.da_mon;
  31.   y2 = d.da_year;
  32.   float t_interest = 0.0;
  33.   if((y2 < y1) || (y2==y1 && m2 < m1) || (y2==y1 && m2 == m1) && (d2 < d1))
  34. return t_interest;
  35.   days = no_of_days(d1, m1, y1, d2, m2, y2);
  36.   int months = 0;
  37.   if (days > 30)
  38.   {
  39.     months = days / 30;
  40.     t_interest = ((t_balance*2)/100 * months);
  41.   }
  42.   file.close();
  43.   file1.close();
  44.   return t_interest;
  45. }
  46.  
  47. int user::no_of_days(int d1, int m1, int y1, int d2, int m2, int y2)
  48. {
  49.   static int month[] = {31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30};
  50.   int days = 0;
  51.   while (d1 != d2 || m1 != m2 || y1 != y2)
  52.   {
  53.     days++;
  54.     d1++;
  55.     if (d1 > month[m1-1])
  56.     {
  57.       d1 = 1;
  58.       m1++;
  59.     }
  60.     if (m1 > m2)
  61.     {
  62.       m1 = 1;
  63.       y1++;
  64.     }
  65.   }
  66.   return days;
  67. }
Apr 2 '12 #1
1 1741
Frinavale
9,735 Expert Mod 8TB
The variable d only exists within the getDate method. It's "scope" is only within the method because it is a parameter for the method. You should probably research the topic of scope because it is very useful and will help you to understand the lifetime and accessibility of variables.

You are getting this error message because you are attempting to use use the d variable outside of the getDate method.

If you replace d with the variable that you pass in to the getDate method, it will fix the problem.

-Frinny
Apr 2 '12 #2

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

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
2
by: Tjerk | last post by:
Hello all, I have the script below to change an image depending on the date upto january it worked fine but then it just stopped working does anybody have an idea how I can make it work again or...
9
by: Thomas R. Hummel | last post by:
Hello, I am importing data that lists rates for particular coverages for a particular period of time. Unfortunately, the data source isn't very clean. I've come up with some rules that I think...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
3
by: captain | last post by:
Below is the sql for data with same date need to extract + or - 5 days data of same date also. How to also get data of + and - days related to same date. SELECT IM.Area, IM.Location,...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a...
3
by: JJ | last post by:
Here's the code. $link="http://xbox360cheat.org"; $close_date=$_POST; #last content change check if ($close_date == 0) $close_date = date("Y-m-d H:m:s", mktime(12, 0, 0, date("m"), date...
9
lilp32
by: lilp32 | last post by:
I am relatively new to Access (using 2010) and this seems like it should be simple yet I can't seem to figure it out. I have aggregate count data from 30+ counting devices (101, 102, etc) which...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.