Hello, First of all I want to thank all the help with my posts.

I have a program where I have to convert a phrase from lower case to upper case, but I cannot use any of the toupper() isupper() functions and vice versa.

I think I almost got it, but I know my for loop for the conversion is incorrect.

Here is my code:

#include <iostream>
#include <string>
using namespace std;





int main()
{
    char beach[] = "Take me to Clearwater Beach!";
    cout << "Initial Phrase: " << beach << endl;

    for (char *i = beach; *i != '\0'; ++i)
    {

        if( i >= "a" && i <= "z")
        i += 32;
        ++i;

    }

    cout << "\n";
    cout << "New Phrase: " << beach << endl;



    return 0;

}

My for loop has to be incorrect, it's not doing any of the arithmetic.

Thanks again!

A character literal uses single quotes, string literals use double quotes. There's a difference, and it's rather significant. ;)

I figured that, but then I kept getting these errors:

C:\Users\""\Desktop\beach.cpp: In function int main()': C:\\Users\\""\\Desktop\\beach.cpp:18: invalid initializer C:\\Users\\""\\Desktop\\beach.cpp:21: no match forbasic_string<char,string_char_traits<char>,__default_alloc_template<false,0> > & != char'
C:\Users\""\Desktop\beach.cpp:24: warning: comparison of distinct pointer types string *' andchar *' lacks a cast
C:\Users\""\Desktop\beach.cpp:24: warning: comparison of distinct pointer types string *' andchar *' lacks a cast

Compare this with your code and see if you can figure out why I made certain changes:

for (char *i = beach; *i != '\0'; ++i)
{
    if( *i >= 'a' && *i <= 'z')
        *i -= 'a' - 'A';
}

You've inspired me to do a pony avatar ha ha

Welcome to the herd. :D

Edited 3 Years Ago by deceptikon

So adding an int value of ASCII wouldn't work, you would subtract the actual char, I guess

This question has already been answered. Start a new discussion instead.