Alright, so I'm trying to write a fraction calculator for the hell of it, here's my problem:
I want the user to enter in two fractions, lets say 64/100 and 55/100
I want then to enter one fraction at a time, in exactly that format. How can I manipulate that string, so I can get the numbers separated by the '/' ?
I've been messing around with strings for a while now, but I can't seen to figure out how to separate it.. Thanks for the tips!
Edit: Okay, I've got some code written to find the /, now I just need to find out how to grab the numbers on either side of it...
I want the user to enter in two fractions, lets say 64/100 and 55/100
I want then to enter one fraction at a time, in exactly that format. How can I manipulate that string, so I can get the numbers separated by the '/' ?
I've been messing around with strings for a while now, but I can't seen to figure out how to separate it.. Thanks for the tips!
Edit: Okay, I've got some code written to find the /, now I just need to find out how to grab the numbers on either side of it...
Code:
// Written by Michael C. Dillon
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
using std::string;
int main ()
{
string first;
char second[50];
unsigned int value;
size_t found;
while (true)
{
cout << "Enter your first fraction: ";
getline(cin,first,'\n');
string::size_type found = first.find("/", 0 );
if (found!=string::npos)
cout << "/ found at " << int(found) + 1 << endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Comment