C/C++ :: For Loop To Print Given Character Number Of Times Specified By Integer
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
ADVERTISEMENT
Feb 19, 2015
I'm trying to determine the number of times I have to change each specific character in a string to make it a palindrome. You can only change a character one at a time from the end.
Example: "abc" -> "abb" -> "aba" should print 2. "aba" will print 0 because it's already a palindrome. "abcd" -> "abcc" -> "abcb" -> "abca" -> "abba" will print 4 because it took 4 changes to make a palindrome.
I'm not too sure how to approach this - I figured out the case where if it's a palindrome (if reversed string is the same) then it'll print out a 0.
int main() {
int number;
cin >> number; //expecting a number for first line user input
for (int i = 0; i < number; i++) {
string str;
[Code] ....
View 1 Replies
View Related
Oct 29, 2013
I have been trying to make a program that asks for username and password, and if it is wrong it will loop back to the top. But i only want it to loop a set number of times, how can i do this? This is my code so far
string username;
string password;
cout << "Enter username: ";
getline(cin, username, '
[Code] ....
View 4 Replies
View Related
Feb 17, 2013
How would I by any means print out the result of one number being added by two numbers 999999 times, the numbers both happen to be about 16500 digits long. It must display ALL digits in the number (all the digits the result ends up being). I know I can't use normal data-types, so what do I do?
Looks kinda like this:
for (int i = 0; i < 999999; ++i)
{
total += a;
total += b;
}
a and b being 2 different numbers with about 16500 digits.
View 2 Replies
View Related
Jan 26, 2014
I am writing for loop with a switch so that scores can be inputted in by a judge. The issue that I am running into is that I will put out an the text then the test happens and the code puts out the switch statement 5 times with random number. Here is what I have written.
Code:
int main() {
int diver;
int option;
int Judge;
cout << "Enter Divers Name:";
[Code] ....
View 4 Replies
View Related
Apr 9, 2014
write a c++ program that reads an unknown number of integer values and then print count, sum and average of odd values, even values, positive values, negative values!!
View 1 Replies
View Related
Feb 6, 2014
In this program what i'm doing is to search for a number when the vector is in order, and count how many times that number appears, the problem is that count how many times the number does not appear, but when its appear the program stays in an "standby mode" and the cursor does not move.
int buscarNumOrdenado (int x [MAX]) //MAX is the define {
int num,d, LimiteInferior, LimiteSuperior,mitad;
d=0;
LimiteInferior = 0;
LimiteSuperior = MAX-1;
[Code] ....
View 2 Replies
View Related
Sep 26, 2012
I'm running a game online and designing a program to generate Enemy Stats. Basically, it's supposed to generate 25 numbers between 0 and 7(to represent 8 Attributes on a 25 Point Buy system) and count how many times each number shows up.
Here's what the code looks like:
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int Generate() {
int r= rand();
int s= r%7;
[Code] ....
And here's two outputs.
1: Code:
12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 Stats[0]= 25 Stats[1]= 0 Stats[2]= 0 Stats[3]= 0 Stats[4]= 0 Stats[5]= 0 Stats[6]= 0 Stats[7]= 0 Stats[8]= 0 Disallowed system call: SYS_socketcall
2: Code:
14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 Stats[0]= 0 Stats[1]= 0 Stats[2]= 0 Stats[3]= 0 Stats[4]= 25 Stats[5]= 0 Stats[6]= 0 Stats[7]= 0 Stats[8]= 0 Disallowed system call: SYS_socketcall
Note that the number does change, but only between runs.
View 3 Replies
View Related
Aug 6, 2013
I create a loop that would repeat itself many times a second? Trying to do extremely basic graphics with a grid and system("cls") every time I run a command, but it still looks very jumpy. I realize system calls are evil. Any way to get rid of this too.
View 1 Replies
View Related
Jan 27, 2015
Assume all variable are declared correctly, the following for loop executes how many times?
for (i = 0; i <= 20; i++)
cout << I;
I think 20 but am not sure.
View 7 Replies
View Related
Nov 28, 2014
I tried my best but I can't figure out the problem. At the last part of "createArray", I output the final array created. I mean it to repeat once but then it repeat more times than I expect. createArray is an iterative function. If it repeats 3 times, than at last the array created which fulfil the criterion would be printed out 3+1 times.
I am trying to create an array with 3 numbers 5 times, resulting in a 2D array. The 3 numbers in a array are picked from 0 - 5. I enter createArray(5,3,5). Then these 5 arrays are compared with each other to see if there are repetitions. If there are, the whole process begins again, 5 arrays with 3 numbers each will be picked again and compared with each other. If there are no repetitions at last, there 5 arrays would be printed out.
void deleteArray(int** array){
delete[] array;
}
int** createArray(int simu_times, int randomrun,int numberofrun){
vector<Int_t>fChosenRun;
int** Array = new int*[simu_times];
[Code] ....
View 8 Replies
View Related
Mar 18, 2014
I'm having trouble getting my loop to work correctly. If I iterate the for loop once it works as expected and displays proper output. When I try to iterate two times or more the program gets stuck in an infinite loop.
testData8.dat:
Code:
12 9
13 756
View 3 Replies
View Related
Mar 5, 2013
How do I make a specific character show up a specific amount of times?
Like I am generating a random number then I need to make "|" show up that many times on the screen.
View 1 Replies
View Related
Feb 20, 2015
I'm trying to create a program that loops "x" number of times, where "x" is going to be a user-input number.
View 2 Replies
View Related
Mar 17, 2015
I want to write how many times a method is called. The first class houses a method that I want to count from the second class how many times it is called. what I am able to achieve so far is that it only writes out how many times it is called but what I want is that it should be like a counter like this: if called ofr 5 times it should print:
1
2
3
4
5
and not just 5.
First class
public static int count = 0;
public void Login(String LoginUsername, String LoginPassword) {
count++;
}
Second class
int i = LoginReusables.count;
i++;
System.IO.File.WriteAllText(@"C:Usersken4wardDesktopTidyWriteLines.txt", i.ToString());
View 11 Replies
View Related
Feb 14, 2014
#include <iostream>
using namespace std;
int main(){
int x;
cout << "Enter character:";
cin >> x;
[Code] ....
If i type in:
+
How come it says that "this is not addition?
View 5 Replies
View Related
Mar 15, 2012
This is my c++ code...the problem is the RESULT is not coming and a bigger number is outputting...I dont know how to convert character to integer..
Code:
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
const int size = 50;
char infix[size],postfix[size],stack[size],dummy='?';
int top=-1;
[Code]....
View 7 Replies
View Related
Sep 20, 2013
I want to have one case of my switch statement to print out how many times the user has chosen other cases in the switch statement. Such as "You have pressed 2 6 times and 4 3 times."
View 3 Replies
View Related
Aug 22, 2014
I wrote the following program shown below that produces a normally distributed random number several times, and then takes the average of them. The problem that I have been having though is that the output it has been producing is 0.0288385 despite the fact that I set the mean of the normal distribution to be 0.1. Why this output value would be so far off from 0.1 despite having averaged over such a large number of random numbers namely 10,000 of them? Also, how to randomly seed this random number generator such that it gives a different value each time its run perhaps by seeding it with the windows timer? Below is the program.
#include <iostream>
#include <random>
using namespace std;
int main() {
default_random_engine generator;
normal_distribution<double> distribution1(0.1,3.0);
double number1,sum,n;
[code].....
View 2 Replies
View Related
Apr 11, 2015
Ok, so I am writing this program with 10 different functions, and one of those functions needs to count how many times 0 appears in a text file. I've done this before, but I am so stumped right now. Should I get the numbers from the 2d array I have, or should I just use the text file here? Here is what I have right now:
int toursMissed(int scores[][COLS]){
int counter;
for(counter=0;counter<=96;counter++){
if(scores==0){
counter++;
return counter;
}
}
View 7 Replies
View Related
Mar 15, 2015
I'm trying to write a function in C that calculates the average test score given by the user an arbitrary number of times...
View 14 Replies
View Related
Feb 13, 2014
how to carry out the conversions. The assignment is the normal hex to octal and Quart (base 4) via bit munipulation which I have worked out myself. However, I have been trying all day to figure out how to read in a string such as H1234, or O4567. How to parse the input I can handle the remainder myself. I'm just stuck and I've tried for hours.
View 5 Replies
View Related
May 23, 2013
I wrote this code purely for educational purposes. It also learn more about how exactly things look in memory. code I have right now ( I will likely add more and change it in the future) .....
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
[Code].....
View 7 Replies
View Related
Oct 31, 2013
Im trying to swap the values of an integer and a character, however Im not sure where to insert the static_cast<type> part that I need for this to happen?
// Program to demonstrate a function template
#include <iostream>
using namespace std;
// Interchanges the values of variable1 and variable2
template<class T>
void swap_values(T& variable1, T& variable2)
[Code] ....
View 5 Replies
View Related
Oct 2, 2013
I have been trying to write a function which can convert a number from an unsigned long integer to a readable ASCII character string. this is what I have come up with, but I am receiving some very strange characters in return. Could the problem be that I am telling a char to = an unsigned long int, (cString[i] = product[i])?
void convertToString(unsigned long con) {
unsigned long product[10];
char cString[10];
const unsigned long begConvert = 10 ^ 10;
[Code] ....
View 4 Replies
View Related
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
View Related