One-Dimensional Array

Can anybody help me with my program? I can't get the example. Here's the question: Create a program that accepts an array of characters. And displays the converted array of characters into Upper case if it is given in
Lowercase and vice versa. Don't use string, but char.

Example: mychar ="I am A conQUeror."
Output --> "i AM a CONquEROR."

My Codes:
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
cout << "Password? \n";
char input[256];
cin.get(input, 256);

for(int i = 0; i < strlen(input); i++)
{
input[i] = toupper(input[i]);
cout << endl << input << endl;
}

for(int i = 0; i < strlen(input); i++)
{
input[i] = tolower(input[i]);
cout << endl << input << endl;
}

getch ();
return 0;
}

Thank you. :)
What your code currently is does is put everything into uppercase (the first for loop) and then puts everything into lowercase (the second for loop), but what the question actually calls for is:

[/b]"...[display] the converted array of characters into Upper case if it is given in
Lowercase and vice versa."[/b]

This means that you instead need to loop through the string once, using the isupper and islower functions to check the case of the letter then switching its case using the tolower and toupper functions.

You also need to #include the cstring header to use the strlen function that you have in your code.
@Keene : Thank you dude. :)
Topic archived. No new replies allowed.