| | |
From java to C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Well another semester has started almost done with all java classes, and now C++ has started. I like it so far it is shorter and somewhat easier code. I have a homework assignment which I have started on, but with just starting C++ not sure where to go. Class meets tomorrow and assignment is due Thursday. A fairly simple enough homework, but I keeping getting stumped, several errors are coming up, and we are just started learning debugging. I am using Visual Studio 2005, its what we're using in class.
Assignment:
Allow a user to input 2 fractions and compute their sum.
such as first fraction: 1/2
second fracton: 2/5
Sum: 9/10
My code:
Assignment:
Allow a user to input 2 fractions and compute their sum.
such as first fraction: 1/2
second fracton: 2/5
Sum: 9/10
My code:
C++ Syntax (Toggle Plain Text)
1. # include<iostream> 2. using namespace std; 3. /* This program will prompt the user for two fractions and then it will figure their sum in a fractional form.*/ 4. int main () 5. { 6. int a; 7. int b; 8. int c; 9. int d; 10. int fraction first = a/b; 11. int fraction second = c/d; 12. cout<< "Enter first fraction;"<<endl; 13. cin>> a/b; 14. cout<< "Enter second fraction;"<< endl; 15. cin>> c/d; 16. cout>> "Sum ="<< ((a*d)+(b*c))/(b*d)<<endl;
Last edited by Ancient Dragon; Jan 21st, 2008 at 1:07 pm. Reason: add code tags
variables a, b, c and d can not be input like that. Do it like this:
you don't need lines 10 and 11, so you might as well delete them because they are wrong anyway.
BTW: Don't manually add line numbers when you post code because it makes it difficult for other to copy/paste into their own compiler for testing. Use code tags, which will add line numbers like this
[code=c++]
// your code goes here
[/code]
cin >> a >> b; You can't type the division symbol, but only the two numbersyou don't need lines 10 and 11, so you might as well delete them because they are wrong anyway.
BTW: Don't manually add line numbers when you post code because it makes it difficult for other to copy/paste into their own compiler for testing. Use code tags, which will add line numbers like this
[code=c++]
// your code goes here
[/code]
Last edited by Ancient Dragon; Jan 21st, 2008 at 1:13 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Nov 2007
Posts: 35
Reputation:
Solved Threads: 1
Hi Here iam pasting code for your question....when u compile it u will get what you want....please reply me if you want more than this..
C++ Syntax (Toggle Plain Text)
# include<iostream> using namespace std; /* This program will prompt the user for two fractions and then it will figure their sum in a fractional form.*/ int main () { int a; int b; int c; int d; cout<< "Enter values for the first fraction;"<<endl; cin>>a>>b; cout<< "Enter values for the second fraction;"<< endl; cin>> c>>d; cout<<"First fraction ="<<a<<"/"<<b<<endl; cout<<"Second fraction ="<<c<<"/"<<d<<endl; cout<< "Sum ="<< ((a*d)+(b*c))<<"/"<<(b*d)<<endl; return 0; }
Last edited by Ancient Dragon; Jan 23rd, 2008 at 8:06 am. Reason: add code tags
![]() |
Similar Threads
- FT Junior Java Developer Needed for Major Media firm in NYC (Software Development Job Offers)
- Java/J2EE Senior Software Engineer (Software Development Job Offers)
- Front-end Java Software Engineer for Digital Video/Media Market Leader (Software Development Job Offers)
- Senior Software Engineer (Java) (Web Development Job Offers)
- Java Software Engineer (Software Development Job Offers)
- Java Front-end Developer Engineer for Stealth Media Start-up (Software Development Job Offers)
- Java Developer Required (Software Development Job Offers)
Other Threads in the C++ Forum
- Previous Thread: C++ problem - new to the language and stuck
- Next Thread: How to learn c++
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion count data delete deploy dll download dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






