Upper case convertion C++ problem solving issue

Well the question is pretty basic... it's-

You are given T names in english letters. Each name will include some of the uppercase letters from A to Z, some of the lowercase letters from a to z and some spaces. You have to transform the name from lowercase to uppercase. The uppercase letters that were uppercase before will remain uppercase and the spaces will also remain in their places.

Input Specification

The first line contains a positive integer T ( 1<=T<=10000 ), denoting the number of test case. The next T lines will contain a name. The length of a name will not exceed 100 characters.

Sample
Input:
5
Hasnain Heickal Jami
Mir Wasi Ahmed
Tarif Ezaz
Mahmud Ridwan
Md Mahbubul Hasan

Output:
Case 1: HASNAIN HEICKAL JAMI
Case 2: MIR WASI AHMED
Case 3: TARIF EZAZ
Case 4: MAHMUD RIDWAN
Case 5: MD MAHBUBUL HASAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  #include <iostream>
#include <math.h>

using namespace std;
int main()
{
    int T,p,i,j;
    cin >> p;
    T=p;
    char nameString [100];
    for(i=0;i<=T;i++){
        cin.getline(nameString,99);
            for(j=0;j<100;j++){
                if(nameString[j]>='a'&&nameString[j]<='z'){
                    nameString[j]='A'+(nameString[j]-'a');
                    continue;
                    i=i-1;

                }
            }

        cout << "Case " << i << ": " << nameString << endl;

    }


}






[Problem]
Now everytime i execute this it prints a "Case : 0" after the T or p input :/ .....And I don't want that to happen....grrrrr
[/Problem]
Ugh, you are aware of toupper() existence, are you?

So what is your problem exactly?
That cases start with 0? Make outer loop start from 1 instead.
That it outputs right after input? You will need to store all input and output them in another loop later.
Well I can't use any library or built in functions...... so toupper() is not for me..........And what my problem is that-why is it printing this? "Case : 0"...... it should not be printed........cause IDK if u have ran it....but if u have u'll know that it first wants how many strings do I wanna convert to upper case letters....The input would be anything in between 1000....Then it should print nothing but should take an input of the string then convert and print......but after taking the T input it print's a "Case : 0".....Than takes the string inputs and prints out "Case 1: HASNAIN HEICKAL JAMI"....... sequally (HASNAIN HEICKAL JAMI for example)...but what i want is that i don't want that "Case : 0" to be printed...why isit printing this on earth????????
Last edited on
I can't use any library or built in functions
You are already using them. getline, stream operations are all library functions.

Ah, it is printing because loops starts with 0 and your code says that it should print "Case <counter>:" on each iteration. Your actual problem is "Why my program don't ask for input on first iteration". And answer is: improper handling of mixed formatted and unformatted input.

Here is information on it: http://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction

To solve your problem add std::cin >> std::ws; before line 12. This will skip all leftover whitespace characters and will allow you to input normally.
YEahhhhhhh,,,,hurrahhh!yippppi............thank u man.....it works like charm......well i had to change somethings a bit.....final code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <math.h>

using namespace std;
int main()
{
    int T,p,i,j;
    cin >> p;
    T=p;
    char nameString [100];
    for(i=1;i<=T;i++){
        cin >> ws;
        cin.getline(nameString,99);
            for(j=0;j<=100;j++){
                if(nameString[j]>='a'&&nameString[j]<='z'){
                    nameString[j]='A'+(nameString[j]-'a');


                }
            }

        cout << "Case " << i << ": " << nameString << endl;

    }


}






Thanks once moreeeeee :)
Topic archived. No new replies allowed.