Hi, Iam writing a code for my class and I cant figure out how to solve it. I will be glad if somebody can teach me how to do something to correct it.
The program is divided it 3 parts. -
switch (symbol)
-
{
-
case '+':
-
read_frac(fraction* f);
-
print_frac(fraction& a_fraction);
-
answer = add(fraction f1, fraction f2);
-
nome = "sum";
-
break;
-
case '-':
-
read_frac(fraction* f);
-
print_frac(fraction& a_fraction);
-
answer = sub(fraction f1, fraction f2);
-
nome= "difference";
-
break;
-
case '*':
-
read_frac(fraction* f);
-
print_frac(fraction& a_fraction);
-
answer = mult(fraction f1, fraction f2);
-
break;
-
case 'x':
-
answer = mult(fraction f1, fraction f2);
-
nome = "product";
-
break;
-
case '/': read_frac(fraction* f);
-
print_frac(fraction& a_fraction);
-
answer = div(fraction f1, fraction f2);
-
nome = "quotient";
-
break;
-
}
-
cout << "The " << nome << " of " << << " and " << fraction << " is "<< answer << "\n";
The bold part if where Iam having trouble. I don't know exactly what I have to do to compile
Thanks ,
doug
7 2791
Hi, Iam writing a code for my class and I cant figure out how to solve it. I will be glad if somebody can teach me how to do something to correct it.
The program is divided it 3 parts. -
switch (symbol)
-
{
-
case '+':
-
read_frac(fraction* f);
-
print_frac(fraction& a_fraction);
-
answer = add(fraction f1, fraction f2);
-
nome = "sum";
-
break;
-
case '-':
-
read_frac(fraction* f);
-
print_frac(fraction& a_fraction);
-
answer = sub(fraction f1, fraction f2);
-
nome= "difference";
-
break;
-
case '*':
-
read_frac(fraction* f);
-
print_frac(fraction& a_fraction);
-
answer = mult(fraction f1, fraction f2);
-
break;
-
case 'x':
-
answer = mult(fraction f1, fraction f2);
-
nome = "product";
-
break;
-
case '/': read_frac(fraction* f);
-
print_frac(fraction& a_fraction);
-
answer = div(fraction f1, fraction f2);
-
nome = "quotient";
-
break;
-
}
-
cout << "The " << nome << " of " << << " and " << fraction << " is "<< answer << "\n";
The bold part if where Iam having trouble. I don't know exactly what I have to do to compile
Thanks ,
doug
Doug-
What part are you having trouble with? Have you tried compiling it? What error message do you get?
You seem to be passing a type as well as it's instance to most methods
eg
instead of -
answer = div(fraction f1, fraction f2);
-
consider
This applies to almost every method you call.
Also, your final print -
cout << "The " << nome << " of " << << " and " << fraction << " is "<< answer << "\n";
-
may not do quite what you want, consider -
cout << "The " << nome << " of " << f1 << " and " << f2 << " is "<< answer << "\n";
-
Okay, thanks for the message. I will try to do that and see if I can compile. Thanks once again,
Doug
I did some corrections and still got an error.
Here is the error that the compile shows: c:\documentos\programas\calculator\fraction\fracti on\calc.cpp(65) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'fraction' (or there is no acceptable conversion).
Here is the code again: - #include <iostream>
-
#include <string>
-
#include "fraction.h"
-
using namespace std;
-
-
fraction mult(fraction f1, fraction f2)
-
{
-
fraction f10;
-
int common;
-
-
f10.numerator = (f1.numerator * f2.numerator);
-
f10.denominator = (f1.denominator * f2.denominator);
-
-
common = gcd(f10.numerator, f10.denominator);
-
f10.numerator /= common;
-
f10.denominator /= common;
-
-
return f10;
-
}
-
-
fraction add(fraction f1, fraction f2)
-
{
-
fraction f10;
-
int common;
-
-
f10.numerator = (f1.numerator + f2.numerator);
-
f10.denominator = (f1.denominator + f2.denominator);
-
-
common = gcd(f10.numerator, f10.denominator);
-
f10.numerator /= common;
-
f10.denominator /= common;
-
-
return f10;
-
}
-
-
fraction sub(fraction f1, fraction f2)
-
{
-
fraction f10;
-
int common;
-
-
f10.numerator = (f1.numerator - f2.numerator);
-
f10.denominator = (f1.denominator - f2.denominator);
-
-
common = gcd(f10.numerator, f10.denominator);
-
f10.numerator /= common;
-
f10.denominator /= common;
-
-
return f10;
-
}
-
-
fraction div(fraction f1, fraction f2)
-
{
-
fraction f10;
-
int common;
-
-
f10.numerator = (f1.numerator / f2.numerator);
-
f10.denominator = (f1.denominator / f2.denominator);
-
-
common = gcd(f10.numerator, f10.denominator);
-
f10.numerator /= common;
-
f10.denominator /= common;
-
-
return f10;
-
}
-
-
-
void read(fraction f)
-
{
-
int numerator;
-
int denominator;
-
-
cout << "Enter your numerator: ";
-
cin >> numerator;
-
cout << "Enter your denominator: ";
-
cin >> denominator;
-
-
}
-
-
void print(fraction a_fraction)
-
{
-
-
cout << a_fraction.numerator << "/" << a_fraction.denominator << endl;
-
}
-
-
-
int gcd (int u, int v)
-
{
-
u = (u < 0) ? -u : u;
-
v = (v < 0) ? -v : v;
-
-
while (u > 0)
-
{
-
if (u < v)
-
{
-
int t = u;
-
u = v;
-
v = t;
-
}
-
u -= v;
-
}
-
return v;
-
}
-
----------------------------------
-
-
-
-
#include <iostream>
-
#include <string>
-
#include "fraction.h"
-
using namespace std;
-
-
int main()
-
{
-
fraction f1;
-
fraction f2;
-
fraction f10;
-
fraction f;
-
fraction a_fraction;
-
-
int answer;
-
char symbol = ' ';
-
string nome;
-
-
while (true)
-
{
-
cout << "+\tADD\n";
-
cout << "-\tSUBTRACT\n";
-
cout << "* or x\tMULTIPLY\n";
-
cout << "/\tDIVIDE\n";
-
cout << "E\tEXIT\n";
-
cout << "What operation do you want to use?: ";
-
cin >> symbol;
-
if (symbol == 'e' || symbol == 'E')
-
exit(0);
-
-
switch (symbol)
-
{
-
case '+':
-
read(f);
-
print(a_fraction);
-
add(f1, f2);
-
nome = "sum";
-
break;
-
case '-':
-
read(f);
-
print(a_fraction);
-
sub(f1, f2);
-
nome= "difference";
-
break;
-
case '*':
-
read(f);
-
print(a_fraction);
-
mult(f1, f2);
-
break;
-
case 'x':
-
read(f);
-
print(a_fraction);
-
mult(f1, f2);
-
nome = "product";
-
break;
-
case '/':
-
read(f);
-
print(a_fraction);
-
div(f1, f2);
-
nome = "quotient";
-
break;
-
}
-
cout << "The " << nome << " of " << f1 << " and " << f2 << " is " << answer << "\n";
-
}
-
return 0;
-
}
-
-----------------------
-
-
struct fraction
-
{
-
int numerator;
-
int denominator;
-
};
-
-
fraction mult(fraction f1, fraction f2);
-
fraction add(fraction f1, fraction f2);
-
fraction sub(fraction f1, fraction f2);
-
fraction div(fraction f1, fraction f2);
-
void read(fraction f);
-
void print(fraction a_fraction);
-
int gcd (int u, int v);
Thank you ,
Doug
Doug-
I'm not sure if those programs were all together or in different files, what is on line 65? Can you post 64,65, and 66?
Is fraction a class you have made? If so, you will have to write your own << code for it - use the function header: - friend ostream& fraction::operator<<(ostream& out, fraction& value);
-
// Order of arguments may be switched
The line of the code that have problem is:
cout << "The " << nome << " of " << f1 << " and " << f2 << " is " << answer << "\n";
}
--
Error message:
c:\documentos\programas\calculator\fraction\fracti on\calc.cpp(65) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'fraction' (or there is no acceptable conversion)
Thanks once again.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Cho |
last post by:
// CHO, JOHN
#include<iostream>
class fracpri{
int whole;
int numer;
int denom;
|
by: bg_ie |
last post by:
Hi,
I wish to write a C program which obtains the system time and hence
uses this time to print out its ntp equivalent.
Am I right in saying that the following is correct for the seconds part...
|
by: evilmonkey |
last post by:
I am very new to programming as well as Java and this is my first post so please forgive me if this is not quite posted correctly. My Problem is that I have only been using scanner to get user input...
|
by: d0ugg |
last post by:
Hi,
I'm did a fraction program for one of my programming classes and it did compile, however when I'm running the program it crashes for some reason that I do not know.
// fraction.cpp
...
|
by: d0ugg |
last post by:
Hi,
I'm doing a FRACTION program for one of my Programming classes and I'm getting some errors that I can't figure it out.
Here is the Assignment:
1. Convert the fraction structure into a...
|
by: d0ugg |
last post by:
Hello everyone,
I'm creating a program that it is suppose to add, subtract, multiply and also divide fractions and after that, the result has to be reduced to the lowest terms.
However, I'm not...
|
by: Semajthewise |
last post by:
Hi All For those of you that helped me with the questions on this... Thank you! I believe I have solved all the bugs in the code and wanted to post the final product. This is a set of code to solve...
|
by: Myxamatosis |
last post by:
we're given an implementation file to base our class of Fraction off of.
Input and output are in the format x/y, with x and y being ints, with the "/" character in the middle.
so to create an...
|
by: frozenfirefly |
last post by:
okay, so the first class of this program is the Fraction class.
and which I supposed to create:
1. method to input numerator & denominator of fraction
2. and a method to reduce the fraction to its...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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,...
|
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,...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |