C/C++ :: Cannot Get Strings To Print When Using For Loop
Mar 24, 2015
I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.
I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?
#include <stdio.h>
int main () {
/* variable definition: */
I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.
I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?
Code:
#include <stdio.h> int main () { /* variable definition: */
I have a problem who must print the sentences who have lenght more than 20 characters. I dont know why, but it prints just the first words. Look what i made.
#include<stdio.h> #include<conio.h> int main()
[Code]....
For instance :
Give the number of sentences : 3
First sentence : I like the website bytes.com Second sentence : I like more the website bytes.com Third sentence : bytes.com
After I compile the program it should print the first two sentences.
This program is supposed to compare 2 strings and print out a 1 if the characters match and a 0 if they dont. It compiles but doesnt give me the correct output.
Code: #include <stdio.h> #include <string.h> void func(); int main () { func(); return 0;
I need access to the string using the int and the int using the string. Or just direct access to one or the other. . . It's just confusing that they're technically mapped to one another but I can't really access either of them.
I am testing HTTP Headers and I have an strange problem. When I get the response of the server, it is the correct one the first time. If I use a for loop to send more than one request and get more than one response, this response seems to be overlapped with the previous ones. To a better explanation of the problem I attach the code I am using and the output generated:
TCPSocket.h ----------- #ifndef _TCPSOCKET_H_ #define _TCPSOCKET_H_ class TCPSocket { private: int localSocket;
[Code] .....
So, a bigger loop, a bigger the response of the server. However, I know the response of the server is always the same.
The code is supposed to take either an int or a string (and their respective vectors) and insert a given int or string into the vector in ascending order. My code works properly for ints, but it's having a problem with strings.
The order I get with the strings given is
penguin banana great jungle
For some reason comparing penguin to banana/great doesn't give the expected result. The template attached only includes the function and the private vectors needed for the function.
template<class T> class orderedList { public: void insert(const T& item); private: vector<T> list; int total = 0;
I would like the following code to print: "Why doesn't this print?" and "I would like to print the sum of nc: 5". What am I doing wrong.
#include <stdio.h> //Use to test ideas and formats// main() { int c, nc; nc = 0;
[code]....
My result as compiled by gcc -o testing testing.c
This prints.
test t1,e2,s3,t4, 5,
I have not figured out how to sum and print as the above code indicates, which complicates my ability to do many of the exercises in "The C Programming Language". I am using a MacBook gcc compiler and X code as well. I cannot get the last two printf functions to work. I did the temperature example with "while (fahr <= upper)" and the printf printed.
I'm attempting to print a series of text from this loop, but for some reason all I am getting is the sum total and the number 1, like this
1 5175.11
When I want to get it for each iteration of the loop. I've cycled over this and compared it to my other loops I've used and I'm lost as to why this isn't working. I also tried using a do while but that didn't work as well.
#include<iostream> #include<conio.h> using namespace std; int main(void){ clrscr();
[Code] ....
I am trying to print ascii characters but problem is If i put a limit in for loop to 255 or more than 126 the output don't stop it keeps on going
I know there is another way to this program but what i want to know this why this happen in this logic....it doesn't happen if a<=125 or less then 125.
Write a count controlled loop than can print "i" char. The user is supposed to input a integer and that integer is how many asterisks there is on the blade, in this case it is 5.
* * ** ** **--------------- ******* ** ** ** * ** * -10 Rows high ** -blade always connects on second row of handle ** ** ** **------------------
I want to create a vertical histogram in my code. I already made it go vertical but not the way I want it.
Example: I want it like this:
Range1 Range2 Range3 Range4
And asterisks under each one, depending on the user input. (My code is below and doing it on here doesn't make it come out correctly)
But what I've managed to do is this:
Range1 * * *
Range2 * *
Range3 * * * *
Range4 * *
Which I don't want. I want everything else to stay pretty much the same since I can only use some features such as Arrays and really basic functions.
Here is my code: (Worked fine last time I used it and I am doing it on Visual Studio 2010 (at uni) and 2013 (on my laptop)).
#include <iostream> //Start of code using namespace std; int MarkValueInput; //Mark entered by user //Counter variables for ranges in While Loop int counterlow; //Counter for low range int countermidlow; //Counter for mid-low range int countermidhigh; //Counter for mid-high range int counterhigh; //Counter for high range
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
I am working on a small simple program my program fills up a air plane with customers there is 2 levels 1 and 2 and it will put that person in the spot depending on being picked.
So far i made a boolean airplane with 10 spots I can enter 1 person into the airplane with no problem but then after he sits down i get a infinite loop? I assume i maybe have to use the continue statement I feel like there is something simple that im missing i want to add more people. here is what i have
I'm trying to make a percentage counter inside a loop, printing each completed percent of the loop as it goes. I've managed to write such code, but when I run it the percentage output breaks down (becomes negative!) for large loops. I have an example below.
Code: #include <iostream> #include <sstream> #include <string> #include <stdlib.h> #include <stdio.h> using namespace std ; int main() {
[code].....
Compiling and running the above yields the output:
I'm new to programming and i'm trying to do a certain task. I want to use a for loop to read certain data from a txt file and print them to a console. I'm trying to read student names and their grades.
Something like 3 // 3 represents the number of students. George 97 Sarah 70 Maya 88
Just working up for the google coding contest to start soon and have been practising some of the test questions however i make correct algorithms but my output is rejected because of the fact that my strings are printed on a new line so i wish to know a method to print strings using a printf statement or any other function on the same line ...
I need to write a ANSI program to print out each command line argument on a separate line using a for-loop. also it need to print the name of the executable .so far I have
Code:
#include <stdio.h> int main(int argc, char **argv) { int i; printf("")
I am programming a translator, and I have it so that it detects words with spaces both in front of and behind them, so I did "string.append(space);" where space equals " ". That added a space to the end, but I still need a space added to the front.
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.