C++ :: How To Prompt User Input Only Letters (a-z)

Mar 1, 2013

How do I have the user enter only letters?

#include <iostream>
#include <limits>
int getInt() {
int x = 0;
while(!(cin >> x))

[Code] ....

But this function prompts the user to only input integer values. I was thinking if I could maybe try tweaking with this one so that the user could only enter letters..no luck though. So how can I have the user input letters only?

View 3 Replies


ADVERTISEMENT

C++ :: How To Prompt User To Input Only Letters

May 12, 2014

I am trying to write a program to get user's input but only accepts alphabetic characters, nothing else and I want it to ask the user to enter a valid word until they have finally entered a valid one. I have the following code for it but it does not work properly.

void CheckBound (char word1[], int SIZE1) {
int i;
int w1[SIZE4]= {0};
int found;
for (i=0;i<strlen(word1);i++) {

[Code] .....

View 2 Replies View Related

C++ :: Create A Program That Will Prompt The User For Input?

Dec 28, 2014

I need to create a program that will prompt the user for an input, then it will save their input to a file and then it will prompt the user to input "Open" and then the file containing their first input, will open up and show their input.

View 19 Replies View Related

C/C++ :: Prompt User To Input File Name To Open

Aug 31, 2014

I'm trying to develop a programme which, amongst other things, prompts the user to enter the filename which is to be opened. This is what my code looks like currently:

char filename[20];
FILE *myfile;

printf("Enter the full file name you would like to open:");
scanf("%s", filename);

[Code] .....

However, this only ever returns File Not Found - the file is stored in the same directory as the program, and I have tried looking up this issue online, to no avail ....

View 2 Replies View Related

C :: Prompt User For Input And Display Character In Every Line

Mar 17, 2013

I am having problems printing "->" on the beginning of each line, im trying to do it as a loop and ending it when the user types "q". also i would like to know how to ignore text from the user when the input begings with a specific character. heres what ive done so far, and not currrently working as expected.

Code:
#include <stdio.h>
int main (void) {
char prompt;
printf("~~~ FRACTION CALCULATOR ~~~

[Code] ....

View 1 Replies View Related

C/C++ :: UDF To Prompt / Read And Validate User Input And Return A Value?

Aug 5, 2014

I'm having a problem with the two while statements in my UDF.

- 1. It will run both while loops twice...?

- 2. It now goes into a continuous loop.

- 3. When it did work, it would only return 1 value to the main()...?

#include <iostream> // for use of "cin" & "cout", endl...
#include <iomanip> // for formatting setw function
#include <cmath> // for the general math computations
#include <string> // for creating descriptive strings
#include <sstream> // used to convert a string to an integer
//user defined function
int userValue (int);

[code].....

View 1 Replies View Related

C++ :: Prompt User For Two Characters - Output Movies That Begin With Input

Nov 24, 2014

I have trouble printing out the movies starting with inputing only two letters.

#include <iostream> //cout, cin, endl,getline
#include <fstream> //ifstream
#include <cstdlib> // exit
using namespace std;

const int NUM_MOVIES = 116792;
struct Movie {

[Code] ....

View 1 Replies View Related

C :: Program That Counts Letters Of 3 Lines Of Input From User

May 26, 2013

So I am writing a program that counts the letters of 3 lines of input from the user. I am using a 3 x 80 character array as the "notepad". Upper and lower case characters are incremented on the same counter array.

Code:

/*Letters in a string*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void countAlphabet(char *);
/*Character counting array*/
int alphabet[26] = {0};

[Code]...

View 3 Replies View Related

C++ :: How To Error Check If User Input Is Letters And Not Numbers

Jun 9, 2014

How do I error check if the user is inputting letters and not numbers? For example, if the user inputs "Lab.txt" I need to display an error message. If they input "Lab2part2.txt" then this is correct and what I want.

I've found a lot of information online on how to error check for numbers or a single letter (EX: 1,2,3, etc. or 'A' 'B' 'C') but nothing for actual WORDS or maybe I should refer to it as a string of characters?

Is there any way to do this? Because my program requires I ask the user to input the name of the file. But the way my code is currently set up is even when the user inputs the wrong file name it still opens the file. I want to prevent this from happening so my thought was to error check user input.

/*Program to determine company's weekly payroll*/

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void OpenTheFile() {
ifstream inputFile;
string filename;
char letter;
int number;

[Code] .....

View 1 Replies View Related

C++ :: List Of Objects - Read Information From Each Object To Compare To User Input Prompt

Apr 19, 2013

I have a list of objects that I need to read information from each object to compare to a user input prompt.

#include "Passenger.h"
#include "Reservation.h"
#include "Aircraft.h"
#include <iostream>
#include <fstream>
#include <string>
#include <list>
using namespace std;
//Function Prototypes
void flightRoster(list<Reservation>&);

[Code] ....

View 1 Replies View Related

C++ :: Reads User Input And Arrange Letters In Ascending Order?

Apr 21, 2014

I am trying to build a c++ that reads user input and arrange letters in ascending order.

for example, if the user input: Hello my name is Moe! the output will be: !aeeehillmmmnoos (ascending order)

my problem is that when i input hello my name is moe the output will be ehllo (not completing other letters) also when i change class size to 50, it outputs unknown weird letters.

This is my code:

#define CLASS_SIZE 10
#include <stdio.h>
#include <iostream>
void bubbleSortAWriteToB(const char a[], char b[]);
using namespace std;
int main(void){
int i;

[Code]...

View 3 Replies View Related

C++ :: Recursive Function - Prompt User To Input Base And Exponent Then Generate Final Answer

Oct 31, 2014

I am studying about recursion by myself and i want to make a recursive function that prompts the user to input the base and exponent and generate the final answer .

#include<iostream>
using namespace std;
int recursive(int x, int y);
int main() {
/*int total=1;
int y, x;

[Code] .....

View 4 Replies View Related

C++ :: Best Way To Prompt User Again After Some Conditions Have Met

Mar 9, 2013

Here is a simple drinks machine programm. It basically consists in the user selecting a drink that it's presented, if the user selects correctly the number representing a certain drink, the machine shows the user what was the drink he selected, after his choise the machine asks for money insertion, if the user inserts the incorrect amount of money, the machine shows an error saying that user need to insert the correct amount of money.

My problem is that, if the user selects a different number other than those presentend, the machine displays an error saying that he needs to choose a valid drink, but i can't find a way to reprompt the user again after the error has been displayed. here's the code.

// ***Drinkins Machine*** by Roxmate
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
// initializes the variables coca, fanta, iced and drink to be used in switch function,so that the user can choose what drink he wants.
int coca = 1;

[code]....

View 5 Replies View Related

C++ :: Prompt User For All Elements Of 3x3 Matrix

Dec 3, 2014

prompts a User for all elements of a 3x3 matrix. Your program should then print the matrix as well as the transpose of the matrix

View 1 Replies View Related

C++ :: Write A Password Prompt That Gives A User Only Certain Attempts

Mar 6, 2015

I'm trying to write this c++ programe:

Write a password prompt that gives a user only a certain number of password entry attempts, so that the user cannot easily write a password cracker.

Using FOR Loop. I know this can be easily done using while loop. But I want to know how to do it with for loop aswell.

Here is what I have so far:

Code:
#include <iostream>
#include <string>
using namespace std;
int main ()

[Code] ....

I don't see where the problem is.. The program just executes and does nothing.

View 9 Replies View Related

C :: Re-prompt User With Switch Statement Menu?

Sep 20, 2013

how to re-prompt a user with a switch statement menu that I prompted them earlier with. There are 4 options and after the user chooses an option the menu is supposed to pop up again unless the user chooses option 4, how do I do this? For reference I'll put up my source code.

Code:
int main(){
int init_bal,choice,balance,investment, donation;
printf("Welcome!

[Code]....

View 2 Replies View Related

C :: How To Prompt User To Scan Numbers Into Array

May 17, 2013

i need to prompt the user of my program to input numbers into an array so that later on these numbers can be added or subtracted with other numbers to form a new array. My problem is I don't know how to make the user input numbers which will then be saved into the array for later use. Here is the parts of my code that relate to the problem:

Code:

float Xv, Yv, Zv, Xu, Yu, Zu ;
float vector1[VECTOR_LENGTH] = {Xv, Yv, Zv} ;
scanf("%1f %1f %1f", &Xv, &Yv, &Zv);
printf("The first element in the array vector1 is: %3f
", vector1[0]);

The point of that printf function is to see if what they have entered is actually registering as what i want it to. This does not work however and the value for this always comes up as 0.

how to scan numbers into an array so that they can be used for later use?

View 9 Replies View Related

C++ :: Prompt A User To Enter M For Male Or F For Female

Dec 24, 2014

I am simply trying to prompt a user to enter M for Male or F for Female. However, when I test run the program (what I've got so far below), any letter inputted is accepted and continues the program..?

#include <iostream>
using namespace std;
int main() {
char gender;
int maleBodyWeight;

[Code] .....

View 2 Replies View Related

C++ :: Program That Asks User To Prompt Integer Number

Nov 18, 2013

Write a program that asks the user to prompt an Integer number and then test whether it is Palindrome Numbers or not.

The following are Palindrome numbers:
1.22
2.333
3.67876
4.44444
5.123454321

View 8 Replies View Related

C :: Fixing Command Prompt File Input

Oct 21, 2014

Im writing program for a rail fence cipher that should run from the command prompt and take in two .txt files, one containing the key for how many rails there should be (between 1 and 25) and the other containing the message to be encrypted. Both of those txt files should be entered from the command prompt, taken in with the program's arguments, not asking the user for input I think I have the logistics of how to get the program to encrypt it worked out, but every time I try to run the program it keeps on crashing.

The program should run when I enter this:./railcipher samplekey.txt samplemessage.txt

I'm pretty sure my issue lies within my first few lines of code, with the main(), or with the FILE*, but I dont know what I would need to change it to for it to work properly.

Code:
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int main(int argc, char **argv[])

[Code]....

View 3 Replies View Related

C++ :: Opens New Command Prompt Window For Input?

Oct 8, 2014

If I compile code which uses cin using the command prompt, then run the compiled program a new window opens when it reaches the cin line of code, for the input. If there is no cin used then all printing happens in the original window. Is there a way to stop this behavior of the opening of a new window?

View 1 Replies View Related

C++ :: Command Prompt Will Not Disappear After Input Names?

Nov 12, 2014

Here is a code snippet which is a bit annoying.

Code:
cout << "Put in the names of people, press q to exit" << '
';
while((cin >> people_inp) && (people_inp != "q")){
Person *p = newPerson(people_inp);

[Code] ....

The problem of this code is when you put in the names(via cin) and press enter command prompt will disappear. What should I do so that Command prompt will not disappear after I input some names? I mean it disappears without you pressing a key.

View 14 Replies View Related

C++ :: Prompt Information From User Then Display Result In One Dimensional Array

Apr 7, 2013

Is it possible to prompt information from user then display the result in a one dimensional array form? If yes, how should i link them together?

View 7 Replies View Related

C++ :: Prompt User To Enter Domain Name - Return Resolved IP Address

Feb 16, 2013

This is a winsock program designed to prompt the user to enter a domain name. The program is then supposed to return to the user a resolved ip address of that domain name. The user should also be able to enter an IP address and receive back a domain name.

While the program prompts the user to enter the domain name, all that is ever returned is error#:0

HTML Code:
// Declare and initialize variables
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib, "ws2_32.lib")
#include <iostream>
int main(int argc, char **argv) {
hostent* remoteHost;

[Code] ....

View 12 Replies View Related

Visual C++ :: Prompt User To Enter Integer Value And Character Code To Indicate Conversion

Sep 14, 2013

I'm expected to write a c program for this question :

Using these header files
#include <stdio.h>
#include <conio.h>

Question : Write a program that will prompt the user to enter an integer value and a character code to indicate whether they want to do a Kilogram to Pounds conversion (A) or a Pounds to Kilogram (B) conversion. Note that 1 kg = 2.2 pounds. The program should then do the necessary conversion indicated by the code and display the newly converted value to the screen.

View 1 Replies View Related

C :: How To Restrict Input Of A String To 2 Letters

Mar 6, 2015

I'm doing error checks in C and I'd like to know how to restrict the input of a string to 2 letters and if it is exceeded, i'd like to loop and ask for the code to be re-entered.

Code:

for (i = 0; i < code7; i++)
{
printf("Enter number of items: ");
scanf("%d", &item_qty[i]);

[Code].....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved