Hello, I am very new to the C++ world (2 months)
I have an assignment where we need to write a program that asks the user for his first name in lowercase, validate it, and return it. Then ask for their last name in lowercase, validate it, and return it. Then return the full name and show how many characters it consist of.
My validation works fine but it's not returning the name.
ie...Please enter your first name in lowercase: mike
Your first name in lowercase is
Here is what I have thus far:
(Also the input of each string must be done through a function and the function must return a Boolean parameter indicating the validity of the input)
//Assignment07, Pointers, Functions, and Input Validation
//Michael
//November, 12, 2008
#include <iostream>
#include <cstdlib>
using namespace std;
bool lowerCase(char *);
void main()
{
char first, last;
bool validLetters;
do
{
cout << "Enter your first name in lower case letters: ";
validLetters = lowerCase(&firs t);
if (!validLetters) cout << "Invalid entry. Try again...\n";
} while (!validLetters) ;
cout << "\n\nYour first name in lower case is: " << first << endl;
do
{
cout << "Enter your last name in lower case letters: ";
validLetters = lowerCase(&last );
if (!validLetters) cout << "Invalid entry. Try again...\n";
} while (!validLetters) ;
cout << "\n\nYour last name in lower case is: " << last << endl;
}
bool lowerCase(char *chars)
{
int i,len;
char buf[100];
bool validLetters = true;
cin.getline(buf ,100);
len = strlen(buf);
i = 0;
while (validLetters && i < len)
{
if ((buf[i] < 'a') || (buf[i] > 'z'))
validLetters = false;
i++;
}
if (validLetters)
{
(*chars) = atoi(buf);
if (((*chars) < 0) || ((*chars) > 100))
validLetters = false;
}
return validLetters;
}
Thank you for your help. And I thought Spanish was rough..lol
I have an assignment where we need to write a program that asks the user for his first name in lowercase, validate it, and return it. Then ask for their last name in lowercase, validate it, and return it. Then return the full name and show how many characters it consist of.
My validation works fine but it's not returning the name.
ie...Please enter your first name in lowercase: mike
Your first name in lowercase is
Here is what I have thus far:
(Also the input of each string must be done through a function and the function must return a Boolean parameter indicating the validity of the input)
//Assignment07, Pointers, Functions, and Input Validation
//Michael
//November, 12, 2008
#include <iostream>
#include <cstdlib>
using namespace std;
bool lowerCase(char *);
void main()
{
char first, last;
bool validLetters;
do
{
cout << "Enter your first name in lower case letters: ";
validLetters = lowerCase(&firs t);
if (!validLetters) cout << "Invalid entry. Try again...\n";
} while (!validLetters) ;
cout << "\n\nYour first name in lower case is: " << first << endl;
do
{
cout << "Enter your last name in lower case letters: ";
validLetters = lowerCase(&last );
if (!validLetters) cout << "Invalid entry. Try again...\n";
} while (!validLetters) ;
cout << "\n\nYour last name in lower case is: " << last << endl;
}
bool lowerCase(char *chars)
{
int i,len;
char buf[100];
bool validLetters = true;
cin.getline(buf ,100);
len = strlen(buf);
i = 0;
while (validLetters && i < len)
{
if ((buf[i] < 'a') || (buf[i] > 'z'))
validLetters = false;
i++;
}
if (validLetters)
{
(*chars) = atoi(buf);
if (((*chars) < 0) || ((*chars) > 100))
validLetters = false;
}
return validLetters;
}
Thank you for your help. And I thought Spanish was rough..lol
Comment