Bluasul
Bluasul

Reputation: 325

Pig Latin converter using toupper

I'm having trouble converting using toupper on the first character in my string.

I used tolower(first[0]) to turn the first letter into lower case.

Why doesn't toupper(first[0]) make the first character upper case?

Also, is there a way to move the first character in a string to the last spot?

Thanks a lot in advance.

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

int main ()
{

  char ans;

  do{

    string first, last;
    char first_letter, first_letter2;

    cout << "This program will convert your name " 
     << "into pig latin.\n";
    cout << "Enter your first name: \n";
    cin >> first;
    cout << "Enter your last name: \n";
    cin >> last;

    cout << "Your full name in pig latin is ";

    for(int x = 0; x < first.length(); x++){
      first[x] = tolower(first[x]);
    }

    for(int x = 0; x < last.length(); x++){
      last[x] = tolower(last[x]);
    }

    first_letter = first[0];

    bool identify;

    switch (first_letter)
      {
      case 'a':
      case 'e':
      case 'i':
      case 'o':
      case 'u':
    identify = true;
    break;

      default:
    identify = false;
      }

    if(identify == true){
      toupper(first[0]);

      cout << first << "way" << " ";
    }

    first_letter2 = last[0];

    bool identify2;

    switch (first_letter2)
      {
      case 'a':
      case 'e':
      case 'i':
      case 'o':
      case 'u':
    identify2 = true;
    break;

      default:
    identify2 = false;
      }

    if(identify2 == true){
      toupper(first[0]);

      cout << last << "way" << endl;
    }

    cout << "You you like to try again? (Y/N)\n";
    cin >> ans;

  } while(ans == 'y' || ans == 'Y');

  return 0;

}

Upvotes: 0

Views: 92

Answers (1)

AliciaBytes
AliciaBytes

Reputation: 7429

Just a simple blunder, compare

first[x] = tolower(first[x]);

with

toupper(first[0]);

usual case of the 'can't see the obvious thing missing' syndrome... I hate those mistakes.

As for moving the first character to the end I'd usually just use substr() for a simple case:

str = str.substr(1) + str[0];

Upvotes: 2

Related Questions