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;
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;
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.
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;
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++) {
#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?
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!
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?
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.
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 ....
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 ~~~
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);
Design an algorithm using flowchart or pseudo-code to prompt the user for a series of positive integer values. Calculate the average of these values and display the average at the end of the program. Assume that the user types the sentinel value -1 to indicate end of data entry.
Sample input-output: Enter a positive integer (-1 to end) : 5 Enter a positive integer (-1 to end) : 7 Enter a positive integer (-1 to end) : 6 Enter a positive integer (-1 to end) : -1
The average value is: 6
I searched online and found out this solution however it is only for three numbers.Is there any way of modifying this to include the sum of x numbers / number of x(integers) to find the average?
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;
I am trying to make a program that will allow a user to enter their name, from this point, three options should be present for the user to choose, then from that point, two more options should be present. I have if else statements in a switch case and I get the "undeclared" error for the a in the first " if(specificage == a) ".
I am trying to write up something to have a user to enter a four digit number. Only four digits, Ex: 0001, 0116, or 9999. There is no getting around the selection 0001 or 0002. I understand if not done correctly, the first three 0's will be ignored.
I've been just playing around with what I have below but I just don't remember how to do it nor can I find a good example online to figure it out. I know it is not correct just typing to try to remember. I am aware that it is gibberish right now, this is just me brainstorming.
int number; cout<<("Please enter the four digit number(Ex: 0001): "); cin>> setw(2) >> number; cout<<)"Please enter four digit date. Two digits for month and two digits for year: "); cin>> date; if (number< || number > 30) cout << "Invalid choice. Try again." << endl; cin.clear();
I'm trying to validate my input. I require for the user to enter six doubles and if they don't then I want them to re-enter the information. Here is my code:
Code: while (1>0) { printf("Please enter arguments in the order: negative mass, positive mass, initial x-position, initial y-position, initial x-velocity, initial y-velocity: ");
if ( scanf("%lf %lf %lf %lf %lf %lf",&MassMinus,&MassPlus,&Pos[0][0],&Pos[0][1],&Vel[0][0],&Vel[0][1]) != 6) { printf("Not all numbers were assigned!
[Code] .....
At the moment it just waits if you enter less than six numbers and if you enter any more than 6 it just ignores anything after the sixth number (so pretty much does nothing). Also if I entered 1 2 a b 3 4 instead of entering six numbers it would register that as 1 2 0 0 3 4 but I want it to make the user input the numbers again. I'm also aware that "while (1>0)" isn't good programming form but I'm not really sure what to use instead?
B. Circle in a Square Write a C++ program that will ask the user to enter the area of a square. Then the program will display the biggest area of a circle that will fit in a given square. Using math.h library is not allowed.
When the user gives no input, they have to press enter twice before "Done." is printed.
cout << "What do you want the name of your page to be? "; std::getline(cin, pageTitle); if (cin.get() == ' ') pageTitle = "Welcome to Website."; cout << "Done. ";
Is there a way to print "Done." after pressing enter once?