C++ :: Program That Will Allow A User To Input Their First Name Into A String
Feb 23, 2015
So we have a weekend assignment that is "Write a c++ program that will allow a user to input their first name into a string, and use the switch/case statement to produce the following output. Your Program should prompt the use rwith the numbers and the options for each (school, classification, and mood) allowing them to make a choice"
My issue is with the output. The output at the end is the number that they input and not the name of the case they chose, so if they chose option 1 for school it does not print out "BRCC" at the end for the output it prints a 1.
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string name;
cout << "Please enter your name: ";
cin >> name;
This program will allow the user to input string then scans the file if it contains the same string given by the user. But i always get "MATCHED" even if i enter random string. I tried and tried to place the if statement in different positions but i dont get my expected output.
Code: #include<stdio.h>#include<stdlib.h> #include<time.h> #include<string.h> int main() { int found;
I have problem with string compare. I want to compare the string user input with a string in binary. And I don't know how to do it. Problem in function login();Here is the code: And you also can download file in attachment too..
I've been agonizing over this all day. The assignment is to capitalize every other word in a user input string.
My logic is as follows:
1. I have the program get each character until it encounters white space (using for loop) 2. Then it should capitalize each character after the white space until it encounters another white space (using while loop).
My problem though is when i try to create a condition for while loop i have to terminate is when white space is encountered, but the very first character to start the while loop is a white space..
I was told to define boolean values, but after trying a few boolean conditions I'm still stuck..
Code: #include <iostream> #include <string> #include <cctype> using namespace std;
I have been reading up on arrays and string array. I created a string string text[0] and it is defined by user input. I am trying to sort the input. I want Michael to read Macehil.
When I wasn't using an array and just a string I did this:
return sort(text.begin(), text.end()); a
And it worked fine. Do I need to change my string into a char? If so, would I static cast that?
I am writing a code in a class that will change the user input which is integer to a string. For example if the user enter 13347..the output should change to "one three three four seven" on the user screen.I'm not getting the right output.
Code below:
#include <iostream> #include <string> using namespace std; string arr[]={"one","two","three","four","five","six","seven","eight","nine"}; class convertTo{ public: int signed num; int convet(){ cout<<"Enter a number to convert to string "; cin>>num;
I would like to understand a function on strings. Below is a code that I took from my teacher where the user inputs a string and prints out the length of the string.
Code: #include <stdio.h> #include <string.h> int main() { char str[100]; int i = 0;
[Code] ....
Now I understand that it returns the count in "int" so my question is:
Let's say i declared
Code: int count = 0; at the beginning of the code and then made Code: count = strlen(str); why wouldn't i have the same result? Is there a way to do it also?
I'm creating a program that takes user input in the form of a string and tests to see if it matches a word. Each correct word will increase their score by one. Here is a portion of the code that is not working.
To me, this looks like it should do a very simple task as intended-take a String, compare it to another, and reset the word if they match or output incorrect if not. But, I'm not sure if there is some quirk in C++ with Strings, because this code always outputs Incorrect. Please try again. and the score never increases. I also tested this by literally setting the strings equal in the code, which still resulted in it not doing what it's supposed to.
I'm trying to write a short program that takes the input from a user and trims any leading/trailing white space, and then checks how many words are in the string. Problem is, I'm only allowed to use stdio.h and stdlib.h. How can I accomplish this? Also, how would I check if any of the characters which were entered aren't either a number, letter, or '-'?
I built a program that accepts two input from the user, using a array inside a loop, it is pass to a function inside a class which will display the two number, the problem is when the user is inputting a number and it is 1 the program continuously as the user to input a number, and when 2 is entered the program ask another number and end, but for example you entered 2 and 3. . . it will then outpu 2 and 4 (so 3 + 1 ) and always the last number is plus one. here is the code.
main.cpp #include <iostream> #include "newclass.h" using namespace std;
I need a program to run that will accept an input for user id. It will take the customer input and capitalize the letters, and return invalid id with the user inputted values. Then if it's valid it will add a counter counting the number of letters and numbers. It will keep track until the user puts in !. It seems when I try to pass values from the array to my toUpper function to capitalize it it doesn't seem to work right.
I am so close to finishing this program of games, but I'm running into some issues while debugging it.
I've attached the google drive folder since there are several files (ignore the ones with [conflict], etc)...
First, I have the main menu using a switch to select the game. The default was set to exit. If initially when immediately opening the program you put in for say, a letter, it would exit like its supposed to. But if you went and played any of the games ], went back to the main screen, and entered a letter then, it would crash. I've put in a testing line to make sure that you enter a number, and not anything else.
Now however, if you play a game and then want to go back to the main menu, it will simply skip over waiting for your response and close the program. The same thing happens in the slot machine, I want to have it spin the slot machine by pressing enter, but it simply skips over the input, and I'm not sure why.
I'm trying to write a program that capitalizes every other word of a user output. (ex: if input is "i love you", the output is "i LoVe YoU").
I am using a for loop (although an if loop might be easier?) and I'm assuming that it is possible to write this program using a for loop (although I may be wrong--maybe only if loops can write this program). I have everything down EXCEPT the last step where I have to print the entire sequence. What i have so far is:
Code: #include <cs50.h> #include <stdio.h> #include <string.h> { // get user input printf("Type a sentence: "); string s = GetString();
[Code] .....
The code above basically only prints out the capital letter (ex: input is "hello", output is "EL"). I don't know how to print out the entire sequence.
Thread 1 does some background work, and thread2 is waiting for the user's input. If I join thread1 then the app can never exit. If I neither join nor detach thread1 then I get "terminate called without an active exception Aborted" which is not a good thing to have. If I do detach on thread1 does thread1 ever terminate? If not, how to terminate it? Also, how do I check if it's terminated or not?
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.
It's a tic-tac-toe program. I haven't finished doing everything I need to for the project, I'm just trying to get certain parts working as I go.
Anyway, my problem: The program will print the board and ask the first player which square they want to mark. Then it will print the updated board, print the question for the second player to input their square choice but not actually stop to let the user enter anything. Instead it prints the board again and then prints the question for player one again -- this time stopping to let them type in their choice.
Here's my code:
#include <stdio.h> // Function prototypes void printBoard(char board[3][3]); int main() { int quit = 0; // Loop so game continues until player quits
[Code] .....
And it looks like this when I run it, as an example:
I have an a problem I need to make lottery random generation program what asks from user how many lines to gerenate random numbers. But i am now stuck.
Console.WriteLine(" choose how many numbers "); int i = int.Parse(Console.ReadLine()); Random randomizer = new Random(); for(int j = 0; j < 7; j++) { i = randomizer.Next(1, 39); } Console.WriteLine("Your random numbers are{0}", i); Console.ReadLine();