d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Help Please
12Next
Add Reply New Topic New Poll
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
May 21 2012 07:00pm
Hey guys currently I'm doing a program that converts Fahrenheit to Celsius and vice versa. The program goes please enter a number followed by a letter ex 20F or 20f or 30C 30c for fahrenheit and celsius.

I have the coniditions down for those but the thing I cant figure out is how to give someone an error message if they enter say 30 CAR or 76 Friends.... something other than just the number followed by an F or C

Can anyone please help me out?

This post was edited by SlayingWhileInt0xicated on May 21 2012 07:20pm
Member
Posts: 5,641
Joined: Apr 13 2006
Gold: 2.00
May 21 2012 07:41pm
show code for one. ( please use code tags )

why not use the same type of logic you used to check for F f C or c? substring may help.

This post was edited by SilverMice on May 21 2012 07:43pm
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
May 21 2012 09:33pm
Quote (SilverMice @ May 21 2012 08:41pm)
show code for one. ( please use code tags )

why not use the same type of logic you used to check for F f C or c? substring may help.


I'm knew with C++

if (number < 0)
cout << "Error! You must enter a positive number!" << endl;

how would some do this for a alphabetic letter?

I'm using system as the variable for f and c

so therefore...

If (system ....what do i put that would mean does not equal... f || [cant i also use && here?] system .... doesnt equal .... c )

This post was edited by SlayingWhileInt0xicated on May 21 2012 09:34pm
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
May 21 2012 09:38pm
would this make sense?

else if (system != 'f' || system != 'F')

then blah blah blah?
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
May 21 2012 09:54pm
Why is this not working..... :( anyone know? I want it to say the you have entered this and This is incorrect ......




it still is accepting 35 CAR
Member
Posts: 2,047
Joined: Oct 26 2009
Gold: 1,513.00
May 21 2012 11:55pm
Duh, do a conditional to check the length of "system" :P

It should be way up at the top

Also, don't call a variable "system". It's too close to reserved words.

e:/ also merge your last two conditional blocks to if system != c, C, f, F

If I recall there is a toUpper method or some such...

This post was edited by TopherJohn on May 21 2012 11:58pm
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
May 21 2012 11:58pm
Quote (TopherJohn @ May 22 2012 12:55am)
Duh, do a conditional to check the length of "system" :P

It should be way up at the top

Also, don't call a variable "system". It's too close to reserved words.

e:/ also delete your last 2 conditional blocks they are deadcode.


I'm sorry can you put this in easier terms lol this is literally my first week with C++
Member
Posts: 2,047
Joined: Oct 26 2009
Gold: 1,513.00
May 22 2012 12:00am
Quote (SlayingWhileInt0xicated @ May 22 2012 01:58am)
I'm sorry can you put this in easier terms lol this is literally my first week with C++


Yeah, you want to look for something like

if(system.length() == 1){

Your code


}
else
>>error message

Also, I practically live on this site for C++ classes : http://www.cplusplus.com/

This post was edited by TopherJohn on May 22 2012 12:01am
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
May 22 2012 12:01am
hmmmm ok thanks! ill try it out
Member
Posts: 10,884
Joined: Jul 7 2007
Gold: 316.00
May 22 2012 09:18am
Still getting stuck on this if (system.length) thing

this is what I did

if(system.length () != 1)
{
cout << "You have entered << temp << system << ". This is incorrect." endl;

i get an error that says: Request for member in 'length' in 'system' , which is of non-class type 'char'
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll