Visual C++ :: Put If Else Statement In Do While Loop - Too Many Characters In Constant
Jul 28, 2013
I'm trying to put an if-else statement in a do-while loop and when I put the correct answer in the if statement I get that error. Here's the program:
#include <iostream>
using namespace std;
int main() {
int answer;
char repeat;
[Code] .....
View 5 Replies
ADVERTISEMENT
Oct 15, 2014
#include <stdio.h>
#include <math.h>
int main(void)
{
[Code]....
That's my code above and I'm getting an error saying that I'm "implicitly declaring library function 'strcmp' with type 'int(const char*, const chat*)". When i run this program and enter in Black for the first prompt, the program stops. I'm trying to make this program so that when I enter Black as the answer for the first prompt, the program will display the value 10.
View 1 Replies
View Related
Oct 5, 2013
I seem to be having a bit of problem with my if statements in a for loop.
My code involves asking the user for the name of an element (chemistry), searching a text file line by line for an element that matches the input, and outputting other information regarding that element.
One line of the text file looks like this: Helium,He,2,4.00
I've tried running the code without the if loop and it outputs normally (If I ask it to output elementname[0] it will output the first element Hydrogen, which is correct.) but I am not sure what goes wrong when I add the if statement. For some reason, it always follows the "else" statement (It always outputs Invalid search even when I input the right elements).
const int ELEMENTS = 118; //number of elements
ifstream File;
string elementname[ELEMENTS], atomicsymbol[ELEMENTS], atomicnumber[ELEMENTS], atomicmass[ELEMENTS];
string elemname, atomsym, atomnum, atommass;
string search;
[Code] ....
View 2 Replies
View Related
Apr 30, 2012
My break; isn't ending the for statement. User should only get 3 choices but they get to input more than 3.
int playGame() {
int count =0; int x = (rand()%10)+1; int y;
for(int i=0;i<3;i++) {
cout << "Guess the number 1-10: ";
cin >> y;
if (x==y)
[Code] ......
View 6 Replies
View Related
Sep 10, 2014
I got insert statment inside loop like this:
if (ds.Tables.Count != 0)
{
for (Row = 0; Row <= ds.Tables[0].Rows.Count - 1; Row++)
InsertLSP(ElemStartTimeInPrograme, ..........) <-----------------------
[Code]....
i would like to check whether first insert call inside ds loop if is failed e.g due to connection problem this will be ended. What is best way to implement that?
View 3 Replies
View Related
Feb 9, 2014
I was wondering how I could use a continue statement that continues in a nested loop. For example if I have
for (int i=0;i<amount;i++) {
for (int j=0;j<I[i];j++) {
for (int k=j+1;k<I[i];k++) {
if (P[i][j]+P[i][k]==C[i]) {
//What should be here?
}
}
}
}
If the condition is met then the most outer loop (in i) should continue to the next iteration.
If i simply fill in continue; in before the comment then it only continues the loop in k so that is not what I want.
View 5 Replies
View Related
Dec 12, 2014
I have more programming before this, but everything else works fine. My else loop has an infinite output. i also want it to output an error message if the value is not an integer and return to the input
cout << "Select number corresponding material for fencing:" << endl;
cout << "wood = 1" << endl;
cout << "stone = 2" << endl;
cout << "aluminium = 3" << endl;
cin >> material;
if (material == 2){
cost = 100 * perimeter;
[code]....
View 7 Replies
View Related
Jun 12, 2014
Basically I'm supposed to use a while loop to generate a random number and use a switch statement to output the appropriate information. I feel like I'm missing a few things that are very simple.
The errors are:
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
warning C4700: uninitialized local variable 'randomNumber' used
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(){
int i = 0;
unsigned int randomNumber;
[Code] .....
View 2 Replies
View Related
Feb 19, 2014
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
class Program
{
static void Main(string[] args)
{ bool[] planeSeats = {false, false, false, false, false, false, false, false, false, false };
[Code]......
View 1 Replies
View Related
May 1, 2015
#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.
View 7 Replies
View Related
Apr 21, 2013
Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :
10*9*8*7*6*5*4*3*2*1
i try to do it but it show me like this :
10*9*8*7*6*5*4*3*2*1*
how do i write to show me like the first one ?
View 10 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
Feb 20, 2015
Can distinguish between character constant and string constant giving examples
View 1 Replies
View Related
Feb 9, 2015
I have to make a function that i'll later be able to use for a ceasar cypher. The letters should shift a user inputted number. This is what I have so far:
char shiftChar(char c, int s) {
char ch = c;
int shift = s;
int newC;
newC = int(ch) + shift;
return newC;
}
The problem with this, is that it doesn't loop back to the start of the alphabet once i get past z.
View 2 Replies
View Related
Oct 28, 2014
So I have been assigned a program that counts keystrokes, alphabetical characters, and vowels. I have the program working as desired but I just can't figure out how to make it end upon ONLY the "return" key being pressed.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ( void ) {
[Code] .....
View 7 Replies
View Related
Oct 21, 2013
I am new to coding and have a question with my if else statement. This is a VERY simple program that I have made something like in Javascript before, but when I do it in C++ it does not work correctly. It displays both the options. Here is my code.
// Practice.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
// Asking for a number {
int x;
[Code] ....
View 14 Replies
View Related
May 3, 2014
Assume you want to use a loop to process an array of characters starting from the beginning of the array. You want the loop to stop when you read the null terminator character from the array. Fill in the loop test condition that will make this work correctly.
index = 0;
ch = array[index];
while ( _____________________________)
{
// process the character
index++;
ch = array[index];
}
View 1 Replies
View Related
Mar 17, 2013
I have a file that is like the following, with patterns of pipes in it:
Code:
||| || | |
| ||| | | |
|| || ||
I have to consider each row of pipe characters to be in blocks of 3 characters each (e.g. - positions 1-3, then 4-6, etc, etc...) but I have to capture all of the pipes, in sequence, like so:
positions 1-3 for lines 1-3, then positions 4-6 for lines 1-3, etc, etc...
How to get this done besides writing severely redundant control structures like loops, one after the other?
View 5 Replies
View Related
Apr 9, 2014
I'm using the Visual C++ Express 2008 and i need to pass as parameters to a function characters coded in UTF 8. My environment is Windows 7. The editor of the VC++ write in UTF 8 or UTF 16? If it writes in UTF 16 how can i change it?
View 2 Replies
View Related
Dec 26, 2014
Im working on my project for college and i want to know how to add sth similar to a chronometer for user to see how much time have passed while entering some characters using cin.getline function.
View 2 Replies
View Related
Mar 20, 2014
so my question is i want to print characters,no string just an array of characters,i do this but it s not working,maybe i have to put the '' at the end?
Code:
int main() {
int i;
char ch[5];
for(i = 0; i < 5; i++) {
scanf("%c",&ch[i]);
[Code]...
View 6 Replies
View Related
Jul 6, 2014
Im supposed to find the common characters between two string characters, assuming that the user wont input duplicate letters like ddog. When I run my code I get an output of a question mark upside down. Here is my code with comments on what each part is supposed to do
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str1[20], str2[20],remp = '