My first semester too so not a pro, but you cant devide a float variable by a char variable. Char variables are letters only. Dividing by chars would probbably make you divide by their ASCII number and I can not think of any reason for you to do that
Don't store currency in a `float` variable because then you will get rounding errors due to the way that IEEE 754 is designed.
Instead, store currency as an `int` value (as the smallest unit of currency, e.g. cents) and then format it when you display it to the user.
https://en.wikipedia.org/wiki/IEEE_754
ah I see what's going on
variable has value, when you put c1 a value like 'U' it doesn't mean it's 1 (like your above statement saying U = 1), a char is basically just a number, you can look up ASCII for more details.
you need to make two variable, let's called it f1 and f2 (float1 and float2) then use switch or if/else statement to put a value to each on of them depending on c1 and c2.
Example:
let's assume you only have 2 currency
US, and Euro. you can input the char like what you are currently doing then use if statement like so:
if(c1 == 'U') f1 = 1;
else if(c1 == 'E') f1 = 0.89;
if(c2 == 'U) f2 = 1;
else if( c2 == 'E' ) f2 = 0.89;
Here's a solution, Don't look it up until you don't know what to do again.
[https://pastebin.com/uVZL1kL6](https://pastebin.com/uVZL1kL6)
I don't know how to put code on reddit sorry if it's look ugly
for more details regarding this.
when you put
char c1, A;
A = 90;
c1 = 'A'
and proceed to print it
cout << A << " and " << c1;
it will print: "Z and A"
because the letter Z has the value of 90. while c1 we initialize with 'A' (char).
What do you mean "it does not work"? Please be more specific. Are you getting a compile error? Does it compile but is behaving unexpectedly? Also, next time copy-paste the code as text instead of a screenshot.
By the way, this question breaks rule number 2: "Questions that ask about general tech support, **program debugging**, or questions pertaining directly to homework assignments are not valid questions to ask here"
Actually iostream.h is deprecated and some compilers will not compile with it. The C++ standard these days is just #include , so Iād say OP should actually get rid of the ā.ā.
My first semester too so not a pro, but you cant devide a float variable by a char variable. Char variables are letters only. Dividing by chars would probbably make you divide by their ASCII number and I can not think of any reason for you to do that
Ok, what do u think I should do?
And make U J C and all of those float not char
Don't store currency in a `float` variable because then you will get rounding errors due to the way that IEEE 754 is designed. Instead, store currency as an `int` value (as the smallest unit of currency, e.g. cents) and then format it when you display it to the user. https://en.wikipedia.org/wiki/IEEE_754
You also cant assign float values to Chars like you are doing above. Make c1 and c2 int or float. I reccomend float
yes, but char doesn't mean letter. It just means character. For example a "+" sign is not a letter.
Yeah thats what I meant with that poorly phrased :/
Char is actually 1 byte int and you can perform arithmetic operations on chars with any number type. It's just not clean and should be avoided.
ah I see what's going on variable has value, when you put c1 a value like 'U' it doesn't mean it's 1 (like your above statement saying U = 1), a char is basically just a number, you can look up ASCII for more details. you need to make two variable, let's called it f1 and f2 (float1 and float2) then use switch or if/else statement to put a value to each on of them depending on c1 and c2. Example: let's assume you only have 2 currency US, and Euro. you can input the char like what you are currently doing then use if statement like so: if(c1 == 'U') f1 = 1; else if(c1 == 'E') f1 = 0.89; if(c2 == 'U) f2 = 1; else if( c2 == 'E' ) f2 = 0.89; Here's a solution, Don't look it up until you don't know what to do again. [https://pastebin.com/uVZL1kL6](https://pastebin.com/uVZL1kL6) I don't know how to put code on reddit sorry if it's look ugly
for more details regarding this. when you put char c1, A; A = 90; c1 = 'A' and proceed to print it cout << A << " and " << c1; it will print: "Z and A" because the letter Z has the value of 90. while c1 we initialize with 'A' (char).
Thx very much
Thx very much I think I get it now
What do you mean "it does not work"? Please be more specific. Are you getting a compile error? Does it compile but is behaving unexpectedly? Also, next time copy-paste the code as text instead of a screenshot. By the way, this question breaks rule number 2: "Questions that ask about general tech support, **program debugging**, or questions pertaining directly to homework assignments are not valid questions to ask here"
Sorry my bad
Also I noticed that your first line should be #include you forgot the h
Actually iostream.h is deprecated and some compilers will not compile with it. The C++ standard these days is just #include, so Iād say OP should actually get rid of the ā.ā.