I need help creating a program that lets the user enter a string into a character array. It should then convert all the lowercase letters to uppercase. I am stuck at
#include
I want to define my variables but i do not exactly know where to start
zachkt- start by finding an example of code in your language that allows the user to input anything, and then output it. This will give you the shell you need to do the input/output (io). Then you can worry about the converting. Most languages have a library that does that. Also helps to specify the language.
i know how to ask for input and get output but i need to define my variables
i am using C ++ microsoft visual studio 2010
so you're asking how to create the variable for the character array? Or can you just use a string? If it's just a string, bring in a string in the most expedient way possible, use a function (i'm assuming there is one in C++) and then make another string to accept the change.
well, the questions says "The program should let the user enter a string into a character array. It should then convert all the lowercase letters to uppercase."
Well, looks like you need to get yourself a character-array then.. if you don't remember look at yournotes/book/google how to define an array..
can this work for my variables const int NUM_LETTERS = 32; char letters [NUM_LETTERS]
wait i can probably use a smaller number lol like 8
sure looks like a char-array to me ;)
I saw a guy do this problem but he was using #include <cstdlib>. Why did he use this? Do i need it?
i really do not remember using that in class
Google says, there's a tolower() in <cctype>... But you can always write the function yourself - you sure that's not what's required from you?
meant to post this too, sry.. -> http://www.cplusplus.com/reference/clibrary/cctype/tolower/
we never went over cctype
Well it's not unusual to use functions, you didn't explicitly learn about - that wouldn't be very efficient anyway. Just look if maybe there's a library out there that already does what you want to do - maybe look at a second.. decide what you like to use and use it.. or write your own, if you don't like what you find.. that's what programming is about. There's always one more way to do it ;) [doesn't mean you should do exotic/non-intuitive stuff, just because you can think of it ^_^]
#include <iostream> #include <string> using namespace std; int main() { const int SIZE =5; char myword[SIZE]; cout << "Enter a 5 letter word "; cin >> myword; cout<<"You entered the word: "<< myword << endl; return 0; } Do you think you can get the rest from there?
yeah thanks a lot. I got a while back tho #include <iostream> #include <string> using namespace std; int main() { // define variables const int string = 9; char letters [string]; char capletters [string]; int i = 0; // get user input string and store it in a character array cout << "Please enter 8 letters." << endl; cout << endl; cin.getline(letters, string); cout << endl; // go through the array // if an element is a lowercase letter, convert it to its uppercase equivalent for (int i = 0; i < string; i++) // checking if character is lowercase. { if(letters[i] >= 97 && letters[i] <= 122) { capletters[i] = letters[i] - 32; // convert to uppercase. cout << letters[i] << "=" << capletters[i]; cout << endl; } } return 0; }
I felt pretty bad retriceto when i got it
hahah you cant curse lol "retriceto"?
Join our real-time social learning platform and learn together with your friends!