yes, that is correct. I have it working now. It is amazing that something so small can take so long make work when you are a newbie to c++
Thanks for the help...
User Profile
Collapse
-
using the operator == to compare array data?
I am almost done, I am haveing a problem with the code below.
...Code:double get_answers() { ifstream answers; fraction user_answers[6], test_answers[6]; fraction f1, f2; //int checks[6]; int score=0; answers.open("testanswers.in"); if(answers.fail()) { cout<<"The test answers are not available" <<endl; exit(1); -
Okay tried it. Now the return is the fraction I enter.
example:
3/4
the decimal value is 3/4.
...Code:float fraction::decimal_value() { float decimal_num=num; cout<< num <<decimal_num<<endl; float decimal_den=den; cout<< den <<decimal_den <<endl; float decimal=(float)(decimal_num)/(decimal_den); returnLeave a comment:
-
Hello,
using static_cast did not work. The function is part of a fraction class I made. Here is how I call it in the main:
the get_fraction() is a local function to the main.Code:case 'D': get_fraction(f1); f1.decimal_value(); cout<<"the Decimal value is ==> " << f1 << endl; break;
f1 is a loacal variable of type fraction...Leave a comment:
-
Hello,
disregard my last message.
display shows
3 3
4 4
after entering 3/4 fraction answeer = 0...Leave a comment:
-
No luck - I am getting an overloaded << error. But you are trying to display num and decimal_num after decimal_num= num?
I am knew to C++ code - not sure I understand....Leave a comment:
-
Sorry, the function is being called correctly, but the num and den are remaining as ints. The answer that is given is 0. I am not sure how to check other then cout the decimal_num and decimal_den to the screen during the operation.
If I enter 2/3 the dispaly shows
2 // cout<decimal_nu m<< endl;
3 // cout <<decimal_den<< endl;
decimal vaule is 0....Leave a comment:
-
I think you were right. After printing num and den bo remain ints. I tried to use the *1.0 but no-joy. Is there another way to convert num and den to double or float just in that function?
Thanks in advance...Leave a comment:
-
Help with fraction to decimal code in C++
Hello,
The following C++ code is what I am trying to use in a fraction class to convert a fraction to a decimal. the num and den are both ints. When I make a call to the function (f1.decimal_val ue()), the return value is 0.
Can any one help with this problem?
...Code:double fraction::decimal_value() { double decimal_num=num; double decimal_den=den; double -
Hello,
Everything is local to the fucntion it is in. The only return is count - how the user scored on the test.
Maybe arrays are not the way to go. Do you have any suggestions?
I am using a fraction class and have been trying to modify mu usage file.
Here is a copy of the menu. You can see how the functions are called.
...Code:choice = toupper(get_user_command());
Leave a comment:
-
-
Point taken about the code.
The question I am asking, is from the functions I am displaying, am I accomplishing what I said I want to do in the initial posting. That is I am trying to fill an array from an input file and having the user fill in the other array with the answers he/she has calculated on their own. Then I am trying to compare the array with the input file answers with the arry filled with the user answers to return a...Leave a comment:
-
How to compare two different arrays.
Good-day,
I am doing a class project in C++ and am having trouble with one of my menu items. I am trying to inplement a test for the user to try in a fraction class/ porgram. I have filled one array with the answers to the test and then am filling the second array with answers form the user. The third array is a bool array and is being filled by comparing the first two arrays and recording correct/ incorrect anwers. In turn, I am counting...
No activity results to display
Show More
Leave a comment: