0

I have the following code which I have been trying get to output ALL capital letters using the toupper function.

My code will build successfully, however all the letters are still lower case when ever I type.

PLEASE HELP ME UNDERSTAND WHAT I AM DOING WRONG!

The following is the code I have gotten to so far, but I need to know where to place the toupper function. Everytime I try to associate it with char c I do something wrong.
-------------------------------------------------------------------------------------------

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

int main (int argc, char *argv[], char **env)
{
	char c, lastc = ' ' ;
	c = cin.get() ;
	do {
		cout.put(c) ;
		
                c = cin.get() ;
	} while ( !cin.eof()) ;
	return 0;
}

Edited by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

4
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
Featured Replies
  • 1

    Remove that line again and put it inside your loop. Put a [icode]cout << c;[/icode] inside your loop and remove the other cin/cout statements. So your loop-block should look like this: [code=cplusplus] { c = toupper(cin.get()); cout << c; } [/code] also [URL="http://www.daniweb.com/forums/misc-explaincode.html"]code-tags[/URL]. Learn to use them. Read More

  • 3

    Or a real C++ solution: [code=cplusplus] #include <iostream> #include <algorithm> #include <string> struct upper { int operator() ( int c ) { return toupper ( static_cast<unsigned char> ( c ) ); } }; int main(){ std::string str = ""; std::getline(std::cin, str); std::transform(str.begin(),str.end(),str.begin(),upper()); std::cout << str; return 0; }[/code] @tkud: code-tags: … Read More

0
#include <stdio.h>
#include <iostream>
using namespace std;

int main (int argc, char *argv[], char **env)
{
	char c, lastc = ' ' ;
	[B]c = toupper(cin.get());[/B]
	do {
		cout.put(c) ;
		c = cin.get() ;
	} while ( !cin.eof()) ;
	return 0;
}

Changed code,added "c = toupper(cin.get());" I believe I have tried this one before too. The program is still just simply typing out lowercase letters only!!!

This one is really frustrating me, I think that I am thinking too hard about it though.

Any other pointers???

Edited by WaltP: And again, Added CODE tags -- look them up!

1

Remove that line again and put it inside your loop. Put a cout << c; inside your loop and remove the other cin/cout statements.
So your loop-block should look like this:

{
    c = toupper(cin.get());
    cout << c;
}

also code-tags. Learn to use them.

Edited by Nick Evan: n/a

-1

You can also use this code snippet if you are confused..
char response[256];
cout<<"Enter a word.."<<endl;
---------------------------------------------
<cin.getline(response,256);
for(int i=0;i<response.length();i++){
response=toupper(response);
}>
-----------------------------------
This code converts 'response' to capital letters.
This is just for the knowing,anyway.

3

Or a real C++ solution:

#include <iostream>
#include <algorithm>
#include <string>

struct upper {
  int operator() ( int c )  
  {
      return toupper ( static_cast<unsigned char> ( c ) );
  }
  
};

int main(){
    std::string str = "";
    std::getline(std::cin, str);
    std::transform(str.begin(),str.end(),str.begin(),upper());
    std::cout << str;
    return 0;
}

@tkud: code-tags: learn to use them

Comments
Missing , but it is good to see the right approach for once.
This article has been dead for over six months. 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.