RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 15612 | Replies: 12 | Thread Tools  Display Modes
Reply
Join Date: Mar 2004
Posts: 218
Reputation: BountyX is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 6
BountyX's Avatar
BountyX BountyX is offline Offline
Code Guru

Re: Pi Approximation

  #11  
Mar 28th, 2004
well .h is deprecated but none the less still there.
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
Reply With Quote  
Join Date: Mar 2004
Posts: 7
Reputation: essentialc++33 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
essentialc++33 essentialc++33 is offline Offline
Newbie Poster

Re: Pi Approximation

  #12  
Mar 30th, 2004
Originally Posted by BountyX
well .h is deprecated but none the less still there.

Thank you guys. You gave me a big hint. I finally got it to work.
see you guys next time. it is a wonderfully you are doing.
thank you again.
Reply With Quote  
Join Date: Mar 2004
Posts: 7
Reputation: essentialc++33 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
essentialc++33 essentialc++33 is offline Offline
Newbie Poster

Help Re: structure

  #13  
Mar 31st, 2004
the third program is one that adds and subtracts two fractions, not necessarily positive, and displays the exact sum or difference in the lowest terms.
Use the c++ construct "struct" to create a data type for the fractions.
This how I do this;

#include <iostream>

using namespace std;

struct frac{int numer, denom;};

frac f_add( frac, frac );

int main( ){

frac r, s, sum;

cout << "Enter the numerator and the denominator of the first fraction separated by a space=> " << endl;

cin >> r.numer >> r.denom;

while (r.numer,r.denom < 0)

{

cout <<"Yes you may enter a negative integer" <<endl;

}

cout << "Enter the numerator and the denominator of the second fraction separate by a space=> " << endl;

cin >> s.numer >> s.denom;

while (s.numer, s.denom < 0)

{

cout <<"Yes you also enter a negative integer" <<endl;

}

cout <<"You have entered "<< r.numer <<" / "<< r.denom << " and " << s.numer<<"/" <<s.denom<<"\n"<<endl;



int gcd = find gcd (r.denom, s.denom);

sum = f_add(r,s);

cout << "The sum of " << r.numer <<"/" << r.denom << " and "<< s.numer <<"/" << s.denom <<" in lowest term is " << sum.numer <<"/" << sum.denom <<".\n";

return 0;

}

frac f_add(frac r, frac s){

if (r=s)

return r;

else if (a=0)

return s;

else if (s=0)

return r;

else if (r>b);

return find gcd (s, r/s);

else

return findgcd (r, s/r);

}



}



I feel like i am doing something wrong but i cannot figure it out! Please help!
I am very confused with the construct "struct":
what do think i need and how to apply it and where?
thank you
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 7:12 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC