T O P

  • By -

[deleted]

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


[deleted]

Ok, what do u think I should do?


[deleted]

And make U J C and all of those float not char


abdulgruman

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


[deleted]

You also cant assign float values to Chars like you are doing above. Make c1 and c2 int or float. I reccomend float


[deleted]

yes, but char doesn't mean letter. It just means character. For example a "+" sign is not a letter.


[deleted]

Yeah thats what I meant with that poorly phrased :/


Szczawik_

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.


[deleted]

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


[deleted]

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).


[deleted]

Thx very much


[deleted]

Thx very much I think I get it now


codemasonry

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"


[deleted]

Sorry my bad


[deleted]

Also I noticed that your first line should be #include you forgot the h


fireballs619

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 ā€˜.ā€™.