Hi I have a minor(I think it is minor) problem with one of my loop. the loop is supposed to uppercase every letters in the word enter but it stop after one letter.
#include <iostream>
#include <stdlib.h>
usingnamespace std;
inlinechar Upper(char a[256]){
int i = 0;
do {
return toupper(a[i]);
} while (a[i] = getchar() != '.');
}
int main (){
char word[256],rep;
cout << "please enter u (for upper) or l (for lower)" << endl;
cin >> rep;
if (rep = 'u'){
cout << "enter the word"<<endl;
cin >> word;
cout << "the word in uppercase :" << Upper(word) << endl;
}
return 0;
}
ahhhhhhh!! thanks!!! i will put the return outside of the loop. thanks a lot.
edit
now this is the changed program and now whatever i write the "cout" is a heart not the the word in uppercase
#include <iostream>
#include <stdlib.h>
using namespace std;
inline char Upper(char a[256]){
int i = 0;
do {
toupper(a[i]);
} while (a[i] = getchar() != '.');
return a[256];
}
int main (){
char word[256],rep;
cout << "please enter u (for upper) or l (for lower)" << endl;
cin >> rep;
if (rep = 'u'){
cout << "enter the word"<<endl;
cin >> word;
cout << "the word in uppercase :" << Upper(word) << endl;
}
return 0;
}
When passing a 1D array, you dont need to specify the size.
You return a[256] which does not contain any valid data.
Even if it did, you will still see only 1 character in the output coz as i said, a function can return only once. And you choosed to return something invalid.
Fix it like this:
Declare the function as void. It does not have to return anything. inlinevoid Upper(char a[]) .
I dont want to upset your reasoning about using do..while and getchar() .
mmmmm I see, but by saying "I dont want to upset your reasoning about using do..while and getchar() ."
do you mean that I have to change the do..while? because I'm trying to uppercase every letters enter until "." is enter, so I think I need it.
thanks for the answer, I will try to work on what you have told me, if I can't make it work I will try something different.
thanks again.