"expected ';' before string constant error"

Hi

I'm building a fraction calculator in C++ & I've ran into the error: "expected ';' before string constant" & I can't figure out whats wrong with it. Here is my code:
_______________________________________________________________________________

int FracPer () {
cout << "You have entered reading fractions & their percentage!" << endl;
cout << "Please enter the numerator: " << endl;
cin >> numer1;
cout << "Please enter the denominator you want to place under " << numer1 << ": ";
cin >> denom1;
frac1 = numer1 "/" denom1;
percent = (numer1 / denom1) * 100;
cout << "The whole fraction you have entered is " << frac1 << " & its percentage is " << percent << ".";
cout << endl << endl;
}
_______________________________________________________________________________

The error is in the line frac1 = numer1 "/" denom1;. Please help me if you can!

Thanks
Jacob Saunders
frac1 = numer1 "/" denom1;

What is that meant for? It's causing the error.

If you're trying to concatenate strings, the syntax to do so with std::string type is "+", as in

frac1 = numer1 + "/" + denom1;
Last edited on
Considering what the OP is doing on the next line, it seems like numer1 and denom1 are numerical values...? So if that's right, just remove the quotes around the / and possibly make sure you doing floating point division if that's what you want.
Ah, if only C++ was PERL. ;)

For this to work, you will need to make a cast from a string type (like std::string) to an integral type, or vice-versa. C++ won't implicitly convert between them.

Here's a way to convert from an int into a string (I'm assuming numer1 and denom1 are numeric).
http://notfaq.wordpress.com/2006/08/30/c-convert-int-to-string/

Good luck!

-Albatross

P.S: Are numer1 and denom1 ints? If they are, you might have some problems with the division.
Here's another way to convert an int into a string: http://www.cplusplus.com/reference/iostream/stringstream/

EDIT: Did anyone else notice that none of these variables seem to be declared in this function? Or am I just missing it?
Last edited on
Topic archived. No new replies allowed.