0

i have to do a code that takes the word from the user and seperate them from uppercase and lowercase.
i had done the code, but the words that are printed out are not as aspected (symbols)

#include<iostream>
#include <ctype.h>
using namespace std;

int main(){

int i=0;
int total_char=0;
cout<<"enter number of characters: ";
cin>>total_char;
char str[total_char];
char uppercase[total_char];
int num_upper=0;
char lowercase[total_char];
int num_lower=0;
char x;

cout<<"enter word: ";
cin>>str;


for(i=0;i<=total_char;i++)
{
    x=str[i];
    if(isupper(x))
    {uppercase[i]=x;
    num_upper++;}
    else
    {lowercase[i]=x;
    num_lower++;}

    }

cout<<"uppercase character: ";
for(i=0;i<num_upper;i++)
cout<<uppercase[i];

cout<<endl<<endl;

cout<<"lowercase character: ";
for(i=0;i<num_lower;i++)
cout<<lowercase[i];

cout<<endl<<endl;

system("pause");
}
2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by lonelyday91
Featured Replies
  • 1
    WaltP 2,905   7 Years Ago

    When you test each character do you really want to use [icode]i[/icode] to save the result? Read More

0

Being a human and not a computer, it helps to give details. What is input? What should be output? What is actually output?

0

the input word: COdes

should output:

uppercase characters: CO
lowercase characters: des

but it output something like this:

uppercase characters: CO
lowercase characters: >Nd

1

When you test each character do you really want to use i to save the result?

Edited by WaltP: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.