Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,237 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,123 people online right now. Registration is fast and FREE... Join Now!




switch or if else statement

2 Pages V  1 2 >  
Reply to this topicStart new topic

switch or if else statement

missy 69
post 8 Mar, 2008 - 03:00 PM
Post #1


New D.I.C Head

*
Joined: 8 Mar, 2008
Posts: 22

hi i have just been given an assignment i know what i want to do just need help with first statement


i need to change A to little a do i use an if else state ment
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 8 Mar, 2008 - 03:13 PM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,170



Thanked 33 times

Dream Kudos: 25
My Contributions


You can use either.
User is offlineProfile CardPM

Go to the top of the page

letthecolorsrumble
post 8 Mar, 2008 - 04:27 PM
Post #3


Student of The Sun

Group Icon
Joined: 7 Nov, 2007
Posts: 550



Thanked 1 times
My Contributions


cpp

char letter1 = 'a'
char letter2 = 'B';

letter1 = letter1 - 32; //will convert 'a' to 'A'
letter2 = letter2 + 32; // will convert 'B' to 'b'



If you think we are helping you in the wrong direction, please post your code and explain in detail what you wish to do.

Welcome to </dream.in.code> Have a great time here smile.gif
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 8 Mar, 2008 - 04:44 PM
Post #4


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


Whenever this topic (converting case) comes up I send people over to www.asciitable.com.

There are several ways that you can convert cases, one way is your use a conditional block (if-else-if or switch etc). The other way is to use a little math (see letthecolorsrumble post).
User is offlineProfile CardPM

Go to the top of the page

missy 69
post 8 Mar, 2008 - 10:20 PM
Post #5


New D.I.C Head

*
Joined: 8 Mar, 2008
Posts: 22

QUOTE(letthecolorsrumble @ 8 Mar, 2008 - 05:27 PM) *

cpp

char letter1 = 'a'
char letter2 = 'B';

letter1 = letter1 - 32; //will convert 'a' to 'A'
letter2 = letter2 + 32; // will convert 'B' to 'b'



If you think we are helping you in the wrong direction, please post your code and explain in detail what you wish to do.

Welcome to </dream.in.code> Have a great time here smile.gif



So for every differnent letter i wishto change i must declare each one seperate?????????????????????????????????????????????????????????????????????????????????????????????????????????????? biggrin.gif
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 8 Mar, 2008 - 10:23 PM
Post #6


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,328



Thanked 57 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


My preference:
toupper
tolower
User is offlineProfile CardPM

Go to the top of the page

zmikeb
post 9 Mar, 2008 - 01:13 PM
Post #7


New D.I.C Head

*
Joined: 1 Mar, 2008
Posts: 27

QUOTE(no2pencil @ 8 Mar, 2008 - 11:23 PM) *

My preference:
toupper
tolower


I agree. This is the easiest way to do it. Just don't forget to #include <ctype.h> in your preprocessor directives.
User is offlineProfile CardPM

Go to the top of the page

missy 69
post 10 Mar, 2008 - 01:30 PM
Post #8


New D.I.C Head

*
Joined: 8 Mar, 2008
Posts: 22

QUOTE(missy 69 @ 8 Mar, 2008 - 04:00 PM) *

hi i have just been given an assignment i know what i want to do just need help with first statement


i need to change A to little a do i use an if else state ment

CAN SOME ONE PLEASE PUSH ME IN DIRECTION ON WHERE TO START I HAVE DONE MY ALGORITHM BUT I CANT CODE IT I WANT TO CHANGE ALL a TO A AND e TO E ETC CAN SOMEONE PROVIDE ME CODE TO CONVERT THE FIRST LETTER PLAESE ????????????????????????????????????????????????????????????????????????????????????????????????????????????
User is offlineProfile CardPM

Go to the top of the page

MorphiusFaydal
post 10 Mar, 2008 - 01:37 PM
Post #9


D.I.C Lover

Group Icon
Joined: 12 May, 2005
Posts: 1,085



Thanked 8 times

Expert In: Hardware, Networking

My Contributions


Dear God. No need to yell. And no2pencil pretty much gave you the solution.
User is offlineProfile CardPM

Go to the top of the page

missy 69
post 10 Mar, 2008 - 04:47 PM
Post #10


New D.I.C Head

*
Joined: 8 Mar, 2008
Posts: 22

QUOTE(MorphiusFaydal @ 10 Mar, 2008 - 02:37 PM) *

Dear God. No need to yell. And no2pencil pretty much gave you the solution.






yes but the link doesnt actually convert out to screen i am really slow at this i have written my algorithm i want to follow but have no idea how to code this
User is offlineProfile CardPM

Go to the top of the page

MorphiusFaydal
post 10 Mar, 2008 - 05:57 PM
Post #11


D.I.C Lover

Group Icon
Joined: 12 May, 2005
Posts: 1,085



Thanked 8 times

Expert In: Hardware, Networking

My Contributions


So store the result somewhere else.

CODE

char foo = 'a';
char bar;

bar = toupper(foo);

cout << foo << endl << bar << endl;


First week of CS kind of stuff.

This post has been edited by MorphiusFaydal: 10 Mar, 2008 - 05:57 PM
User is offlineProfile CardPM

Go to the top of the page

jhedz
post 11 Mar, 2008 - 06:07 AM
Post #12


New D.I.C Head

*
Joined: 11 Mar, 2008
Posts: 5

missy if you want to change an uppercase letter to lowercase just use the tolower function()...okie
i hope i may gonna help you...
goodluck!!!

CODE
//Example reads in a character and makes up lowercase
#include <iostream>//library for cout
#include <cctype>//librabry

using namespace std;//standard

int main()
{
    char x;//declaration variable for x
    cin>>x;//input the x
    x=tolower(x);//it will lowercase the uppercase letter
    cout<<x;//it will display the lowercase letter
}

Mod Edit: added code tags: code.gif
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 11/21/08 09:38PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month