* RE: Cannot access memory at address 0x140018000
@ 2004-09-13 16:22 lrtaylor
0 siblings, 0 replies; 2+ messages in thread
From: lrtaylor @ 2004-09-13 16:22 UTC (permalink / raw)
To: learning_c, gcc-help
It would be easier if you said what line it was crashing on.
Thanks,
Lyle
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of learning c++
Sent: Sunday, September 12, 2004 7:42 AM
To: gcc-help@gcc.gnu.org
Subject: Cannot access memory at address 0x140018000
Hi,
I can run this program with my computer. But if I use GDB to run it step
by
step. there is always an error:
Cannot access memory at address 0x140018000
What is wrong with the code and the reason?
Thanks,
/* This program allows the user to enter to fraction and then.
the program will print the fraction added together and reduced */
#include<iostream>
using namespace std;
void ReadFraction(int &Num, int &Denom, int &Num2, int &Denom2)
/* This function will allow the user to enter two fraction. */
{
cout << "Enter the numerator for the first fraction: ";
cin >> Num;
cout << "Enter the denominator for the first fraction: ";
cin >> Denom;
cout << endl;
cout << "Enter the numerator for the second fraction: ";
cin >> Num2;
cout << "Enter the denominator for the second fraction: ";
cin >> Denom2;
cout << endl;
}
void Reduce(int &Num, int &Denom, int &Num2, int &Denom2)
/* This function is called after ReadFraction(). This function will
reduce the two fractions.
Pre: Two Fractions
Post: Two reduced fractions */
{
int a, b, c, d, i, j = 0;
a = Denom;
b = Num;
c = Denom2;
d = Num2;
for (i = a * b; i > 1; i--)
{
if ((a % i == 0) && (b % i == 0))
{
a /= i;
b /= i;
}
}
for (j = 50; j > 1; j--)
{
if ((c % j == 0) && (d % j == 0))
{
c /= j;
d /= j;
}
}
Denom = a;
Num = b;
Denom2 = c;
Num2 = d;
}
void Reduce(int &Num, int &Denom)
/* This function is called from AddFraction(). The fraction added in
AddFraction() is reduced here.
Pre: One fraction added from two
Post: A reduced fraction */
{
int a = 0;
int b = 0;
int i = 0;
a = Denom;
b = Num;
for (i = 50; i > 1; i--)
{
if ((a % i == 0) && (b % i == 0))
{
a /= i;
b /= i;
}
}
Denom = a;
Num = b;
}
//-------------------------------------------------------------------
void AddFraction(int &Num, int &Denom, int &Num2, int &Denom2)
/* This function is called after Reduce. This function adds the two
fractions Reduce() reduced
Pre: Two Fractions*/
{
if (Denom != Denom2)
{
Num = Num * Denom2;
Num2 = Num2 * Denom;
Denom = Denom * Denom2;
Denom2 = Denom2 * Denom;
Num = Num + Num2;
}
else
{
Num = Num + Num2;
}
Reduce(Num, Denom);
}
void DisplayFraction(int &Num, int &Denom)
/* This function displays the reduced and added fraction. This
function is called after AddFraction()
Post: Prints fraction */
{
cout << "The reduced and added fraction is " << Num << "/" <<
Denom
<< endl;
}
int main()
{
char an;
do
{
int Num, Denom, Num2, Denom2 = 0;
ReadFraction(Num, Denom,Num2,Denom2);
Reduce(Num, Denom, Num2, Denom2);
AddFraction(Num, Denom, Num2, Denom2);
DisplayFraction(Num, Denom);
cout << endl;
cout <<"Would you like to do another fraction? ";
cin >> an;
cout << endl;
} while ((an == 'y') || (an == 'Y'));
return(0);
}
_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus
^ permalink raw reply [flat|nested] 2+ messages in thread
* Cannot access memory at address 0x140018000
@ 2004-09-12 13:41 learning c++
0 siblings, 0 replies; 2+ messages in thread
From: learning c++ @ 2004-09-12 13:41 UTC (permalink / raw)
To: gcc-help
Hi,
I can run this program with my computer. But if I use GDB to run it step by
step. there is always an error:
Cannot access memory at address 0x140018000
What is wrong with the code and the reason?
Thanks,
/* This program allows the user to enter to fraction and then.
the program will print the fraction added together and reduced */
#include<iostream>
using namespace std;
void ReadFraction(int &Num, int &Denom, int &Num2, int &Denom2)
/* This function will allow the user to enter two fraction. */
{
cout << "Enter the numerator for the first fraction: ";
cin >> Num;
cout << "Enter the denominator for the first fraction: ";
cin >> Denom;
cout << endl;
cout << "Enter the numerator for the second fraction: ";
cin >> Num2;
cout << "Enter the denominator for the second fraction: ";
cin >> Denom2;
cout << endl;
}
void Reduce(int &Num, int &Denom, int &Num2, int &Denom2)
/* This function is called after ReadFraction(). This function will
reduce the two fractions.
Pre: Two Fractions
Post: Two reduced fractions */
{
int a, b, c, d, i, j = 0;
a = Denom;
b = Num;
c = Denom2;
d = Num2;
for (i = a * b; i > 1; i--)
{
if ((a % i == 0) && (b % i == 0))
{
a /= i;
b /= i;
}
}
for (j = 50; j > 1; j--)
{
if ((c % j == 0) && (d % j == 0))
{
c /= j;
d /= j;
}
}
Denom = a;
Num = b;
Denom2 = c;
Num2 = d;
}
void Reduce(int &Num, int &Denom)
/* This function is called from AddFraction(). The fraction added in
AddFraction() is reduced here.
Pre: One fraction added from two
Post: A reduced fraction */
{
int a = 0;
int b = 0;
int i = 0;
a = Denom;
b = Num;
for (i = 50; i > 1; i--)
{
if ((a % i == 0) && (b % i == 0))
{
a /= i;
b /= i;
}
}
Denom = a;
Num = b;
}
//-------------------------------------------------------------------
void AddFraction(int &Num, int &Denom, int &Num2, int &Denom2)
/* This function is called after Reduce. This function adds the two
fractions Reduce() reduced
Pre: Two Fractions*/
{
if (Denom != Denom2)
{
Num = Num * Denom2;
Num2 = Num2 * Denom;
Denom = Denom * Denom2;
Denom2 = Denom2 * Denom;
Num = Num + Num2;
}
else
{
Num = Num + Num2;
}
Reduce(Num, Denom);
}
void DisplayFraction(int &Num, int &Denom)
/* This function displays the reduced and added fraction. This
function is called after AddFraction()
Post: Prints fraction */
{
cout << "The reduced and added fraction is " << Num << "/" << Denom
<< endl;
}
int main()
{
char an;
do
{
int Num, Denom, Num2, Denom2 = 0;
ReadFraction(Num, Denom,Num2,Denom2);
Reduce(Num, Denom, Num2, Denom2);
AddFraction(Num, Denom, Num2, Denom2);
DisplayFraction(Num, Denom);
cout << endl;
cout <<"Would you like to do another fraction? ";
cin >> an;
cout << endl;
} while ((an == 'y') || (an == 'Y'));
return(0);
}
_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-09-13 16:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-13 16:22 Cannot access memory at address 0x140018000 lrtaylor
-- strict thread matches above, loose matches on Subject: below --
2004-09-12 13:41 learning c++
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).