C/C++ :: Get Name Of User And Print It But Only Getting First Character?
Jun 12, 2014
I was trying to get the name of the user and print it but the only thing that i get is the first Character. For example, in this code, i try to get the name of the user and print it.
#include <iostream.h>
int main(){
char name;
cin >> char;
cout<< "welcome " << name;
return 0;
}
should i define "name" in another way?
View 3 Replies
ADVERTISEMENT
Feb 11, 2014
The function uses a "for" loop to print the given character the number of times specified by the integer.
How can I make a for loop to do that?
So.. my code looks like this:
// cpp : Defines the entry point for the console application
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void printMyInteger(int myInteger, char myChar) {
[Code] ....
So.. here is my error:
Error1error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
Error2error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
3IntelliSense: expected an expressiond:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp107Week 6
View 3 Replies
View Related
Jan 10, 2014
How to do this?
View 10 Replies
View Related
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
Jul 2, 2013
int main() {
char StudentName[4][10] = { "Hermine", "Paul", "Gertrude", "Leon" };
cout << "Student Names";
cout << "
Student 1: " << StudentName[0];
[Code] ....
This code work fine...but i want to take name from user..how i store it in character array through getline()..
View 6 Replies
View Related
Apr 29, 2012
Question simple like that: Let user enter some words from keyboard, one word per line until a '.' (period) entered then print out result, for example:
Code:
Enter a word: word1
Enter a word: word2
Enter a word: .
You have entered 2 word(s):
word1
word2
Problem is I don't know how to declare the array of character at the beginning since I don't know neither how many word user may enter nor how many letter of each word. So I go ahead and declared like this: char word[20][50] but I know it is not best way.
Code:
int main () {
char word[20][50]; //array has maximum 20 words, each word maximum 50 character
int i=0, number_of_word;
do {
printf ("Enter a word: ");
[Code] ....
View 3 Replies
View Related
Sep 10, 2013
I'm trying to get the hang of the declaration and use of char. I'm trying to write a program that reads sentences from the user and changes them based on their character choices, I keep getting load of compiler errors.......am I off to a good start or am I way off?
#include<iostream>
#include<string>
#include<cstring>
#include<cctype>
using namespace std;
int main() {
char *quit*;
char sentance [100];
[Code] ....
View 3 Replies
View Related
Aug 8, 2014
How can I create in my C++ program so a user can paste a text and then choose a character on specific line and place?. The above thing isn't that important. I just want to place a character on a specific line and place.
I mean something like this:
Enter a character:
You choosed " / "
On which line do want the character?
You choosed "Line 1 and 2"
Where do you want the the to appear on the line? (left or right)
You choose left.
Results:
Line 1. / hello
Line 2. / hello
View 8 Replies
View Related
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
May 17, 2014
Create a program that will ask the users name, age, and reddit username. have it tell them the information back, in the format: your name is (blank), you are (blank) years old, and your username is (blank).
So I started making my program
#include <stdio.h>
int main(int argc, char* argv[]) {
char name;
int age;
char username;
printf("Please input your name,your age,and reddit username");
scanf(" %c %d %c", &name, &age, &username);
printf(" %c %d %c", name, age, username);
return 0;
}
My program outputted H 0 and an upside down question mark. I was thinking that maybe the error in the program was that i was supposed to use %s instead of %c but im not entirely too sure.
View 14 Replies
View Related
Oct 2, 2014
I'm working my way through some C exercises to get some practice and have hit a wall. I need to use a function to take a number, such as 1, and print out One.Here's what I've got so far:
Code:
#include <stdio.h>
int name(int n);
char numberOne[] = "One";
int main(void)
{
int n;
}
[code]...
However, when I run the code and enter "1" the only thing that gets printed to the screen is "(lldb)". I've tried changing it to doing it without variables and just printing "One" but that gave the exact same result.
View 6 Replies
View Related
May 20, 2014
Write a C program that accepts 8 user input ratings on a new game. Print the lowest and highest ratings received. Use functions.
When i put in values to test the data it's not replacing highest or lowest it's just saying "The highest is 0.0" "The lowest is 0.0"
[#include <stdio.h>
double LowestAndHighest (double num);
void main(){
double num;
double RatingReceived =LowestAndHighest(num);
printf ("%lf", RatingReceived);
[Code] ....
View 1 Replies
View Related
Oct 7, 2014
I tried to work on this program for while, but I am not able to get it to work
Directions:Write a program that reads an integer n from the user.
Display the first 100 numbers, with newlines every n numbers, using % operator
#include <stdio.h>
int main(void){
int a = 0;
int b = 99;
printf("Enter a number: ");
scanf ("%d", &a);
[Code] ....
When I run this code it asks me to enter a number. It doesn't matter what number I enter it gives me the numbers from 1 to 100 in one horizontal line.
I want this program to do something like this:
for example if the user enters n=6 the program should give:
0 1 2 3 4 5 6
7 8 9 10 11 12 13
and so on
View 2 Replies
View Related
Apr 29, 2014
I want to write a program to read in 15 integers from the user, and then store them in a 5x3 array, and print out the numbers as a 3x5 array.
View 7 Replies
View Related
Sep 14, 2014
I keep getting this warning message and I do not know how to fix it. Is it because I'm using char to instead of strings to replace all 't' with 'lp'?
#include<iostream>
#include<string>
#include <stdio.h>
using namespace std;
char * scanf(char * a) {
[code]....
View 6 Replies
View Related
Jul 25, 2012
Double values are stored in text file. 23.5 36.8 34.2 ... My teacher told me to read them character by character and then make words, like i have to read "2" "3" "." "5" and now have to make it or treat it as word and then using atoi(). I have to convert it into double. but i dont know how to do this....
View 5 Replies
View Related
Nov 10, 2013
I have to optimize a code for below scenario. I am reading stdin (a file redirected to stdin) character by character. How many chars are going to come is not known. After every few chars there is a seaparator. e.g $ as below
rhhrkkj$hghjhdf$ddfkrjt
While reading, if the separator arrives I'm processing the string stored before that separator and then continue reading stdin in same fashion, till EOF. I am using getc(stdin) to read chars.
Using gprof I can see most of the program time is spent inside main() , for this reading logic. Rest of the program is just some insert and search operations. I am getting time of 0.01 secs at the moment, want to reduce further.
View 6 Replies
View Related
Aug 10, 2012
How do I write an a program that will read an input file character by character?
View 1 Replies
View Related
Nov 3, 2013
I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....
EXAMPLE
user enters 55
printf("The 55th prime number is %i", variable");
View 1 Replies
View Related
Oct 24, 2013
I'm learning programming, and C++. I've got a question, but I couldn't solve my problem so far. I need to use arrays and only basic stuff to solve this:
Create a program that reads a word from the user and then print (cout) this word on contrary. It's simple, I know, but I can't do it,. I've tried some stuff but I don't get how I will get the proper values to do this. All I know is that I can use variable.lenght().
View 7 Replies
View Related
Oct 6, 2013
In my program, I'm supposed to read a text file (the name of which is given to me as a command line paramater, as long with an integer), and display the text in a specific format (each line can only be as long as the integer). However, I'm having trouble even reading the text file. I don't know the syntax. I'm only allowed to edit the function that does the formatting, and the code in that is
void typeset (int maxWidth, istream& documentIn)
I don't know how to 'read' the file, as most examples online are ifstream, or openFile or something like that. What I want to do is just read the first character of the file, and continuously keep reading characters until the end of the file.
View 10 Replies
View Related
Sep 13, 2014
So I'm trying to create a function that replaces any instance of a character in a string with another. So first I tried the replace() string member function:
In my implementation file
void NewString::ReplaceChar(const char& target,const char& entry)
{
this->replace(this->begin(),this->end(), target, entry);
};
Main program
#include "NewString.h"
using namespace ...;
int main()
[Code].....
Instead of replacing the the l's with y's it outputted a long string of y's. Also, NewString is derived from the string class (it's for the assignment). the header and whole implementation file, already tested.
I've also tried, instead, to use a for loop in ReplaceChar() but I need to overload the == operator and I don't know how I should exactly:
bool NewString::operator ==(const char& target)const {
if(*this == target)
return true;
[Code]....
I want the == operator to test if the value in the char array is equal to target but I'm not sure how to pass in the position. I'm guessing the this pointer in ReplaceChar() is not the same as the one dereferenced in ==() because target is never replaced by entry in the string.
View 5 Replies
View Related
Jul 4, 2014
Can we do this :
Code:
char strings[][100]={"ABC","EFG","IJK","LKM"};
char temp[100];
temp=strings[1];
View 3 Replies
View Related
Nov 17, 2013
I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort
Code:
void Sort(int ary[], int size)
{
int temp;
int smallest;
int current;
int move;
}
[code]....
put it wont print the numbers sorted when I use my print function, just the unsorted numbers.
View 1 Replies
View Related
Sep 1, 2014
is there a to use printf to print certain number of blank spaces, where the number is derived from the output of a function?
for(m=low; m<=high;m++)
{
printf("t=%2d %'f(m)-1's %3c", m, ' ',*);
}
This is suppose to output
t=-3 *
t=-2 *
t=-1
.
.
.
View 2 Replies
View Related
Nov 1, 2014
I am making program that allows the user to determine how big the array size will be and then asks the user to make up numbers to fill the array. Every time run the program on Dev C++ it says "program has stopped working"
Heres My Code:
//Assignment 19 Program 2
#include <iostream>
using namespace std;
int main()
[Code].....
View 3 Replies
View Related