C++ :: For Loop To Count Down From 10 To 0

Apr 16, 2013

I am using a for loop to count down from 10 to 0 it's working to count down from 10 to 1 but when the program cames to the 0 then the program freezes by any reason.

Code:
#include <iostream>
using namespace std;
int main()
{
int number[2];
cout << "Enter number: ";
cin >> number[0];
if (number[0] == 1)

[Code] ....

View 11 Replies


ADVERTISEMENT

C++ :: Count Function - Nested Loop Output

Feb 28, 2013

What does the following nested loop output ?

count = 1;
while (count <= 11) {
innerCount = 1
while innerCount <= (12 - count) / 2) {
cout << " ";
innerCount++;
} innerCount = 1;
while (innerCount <= count) {
cout << "@";
innerCount++;
} cout << endl;
count++;
}

View 9 Replies View Related

C++ :: Count Controlled Loop Than Can Print Char

Sep 27, 2012

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
**
**
**
**------------------

These are the steps he told us to do it in.

1) *
**
***
****
*****

2) *
**
***
****
*****
****
***
**
*

3) * *
** **
*** ***
**** ****
**********

4) * *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *

5)* *
** ** **
*******
** ** **
* ** *
**
**
**
**
**

View 4 Replies View Related

C/C++ :: Count Number Of Digits In Long Variable - While Loop

Aug 3, 2014

So I have been given and as part of the solution I need to count the number of digits in a long long variable. To do this I use a while loop, but it is behaving strangely. Here is the code.

#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main (void) {
printf("What is the card number?");
long long card = GetLongLong();
if(card <= 0)

[Code] .....

When I execute the program it asked for the number, but then nothing happens. Of course, my first instinct was that the program was caught in an infinite loop somehow, but could not figure out how. I commented out the while loop and the program completed (albeit returning the incorrect value), so I was further convinced that there was an infinite loop that I was not seeing. I ran the program throug gdb. Strangely, the program did not loop infinitely, instead it got to line 16 [while(card1 > 0] and then just stopped, it was not executing the next line of code at all.

View 6 Replies View Related

Visual C++ :: Program That Count From 1 To 12 And Print Count And Its Square For Each Count

Dec 16, 2014

4.1 Write a program that will count from 1 to 12 and print the count, and its square, for each count.

4.2 Write a program that counts from 1 to 12 and prints the count and its inversion to 5 decimal places for each count. This will require a floating point number.

4.3 Write a program that will count from 1 to 100 and print only those values between 32 and 39, one to a line. Use the incrementing operator for this program.

View 2 Replies View Related

C :: Loop Does Not Work And Program Quits Without Displaying For Loop Function

Oct 13, 2014

We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.

View 11 Replies View Related

C# :: Use Loop To Load Two Forms Back And Forth Then Stop At Loop 4

Feb 15, 2015

I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.

Here is form1 and form2 code. I have commented out a few things I have tried.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 3 Replies View Related

C :: Extra Loop Being Executed In Do-while Loop

Jul 1, 2013

Code:
#include <stdio.h>
#include<ctype.h>
void try5t(){

char choice;
int choiceint;

[Code] .....

Loop is repeated an additional time as shown in the screenshot:

View 9 Replies View Related

C++ :: How To Count Letters

Mar 16, 2013

I'm just trying to find out if the way I've setup my code currently allows me to count the letters as they occur? I don't yet see how to do it but I need clarification. Ideally the function letterCounter would do the counting but atm I'm just trying to figuring it out in the display function.

View 2 Replies View Related

C/C++ :: Print To LCD - Count Up To 100 Then Down To 1

Feb 12, 2014

I have the following code to print a string to the LCD using my PIC32 Starter Kit; I have made this code work with success. I cannot, however, make the LCD print numbers.

#include<p32xxxx.h>
#define LCD_PRT PORTE //LCD DATA PORT
//#define LCD_DDR DDRE//LCD DDR
//#define LCD_PIN PINE//LCD PIN

[Code].....

I want to change the original code as little as possible, don't worry about my header files - they are fine.

View 2 Replies View Related

C/C++ :: Cannot Count 2D String

Mar 16, 2015

i couldn't count the 2d string. my string is list[100][100] = {"Batuhan","Jeyhun","Tashtanbek"} this is a food line in cafeteria. i want to add a person to this list but i couldnt do it because i dont know the length of my list. it will be more than 3 after i add a person but what if i would add another person after that ? In that case i couldnt be able to tell how long is my line.And after i add people to my list i want to print that list. here is where i came so far:

case 1:
printf("Enter the name of the person to be added
");
printf(">>");
k=0;

[Code].....

View 4 Replies View Related

C++ :: Count The Repeated Numbers?

Jul 12, 2013

I am using this code that to check a set of values from a text file and show it on the output.

Code: void MatchNumber(int b) {
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");
double x1,y1,x2,y2;
while(theFile >> x1 >> y1 >> x2 >> y2 ){
rects.push_back(Rect(x1,y1, x2,y2));
}
int num=0;

[code]....

I want to calculate how many times the common number is repeated . So I have used freq[num] in that function. But I am getting the output like this-

Code:

The common number is = 5
The 5 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times

The common number is = 4
The 4 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

[code]....

So the freq[num] is only returning 1 instead of counting the total number of repeating which is wrong!! I would like to have somthing like this in my output -

Code:

The common number is = 5
The common number is = 6
The common number is = 4
The common number is = 5
The common number is = 5
The common number is = 8
The common number is = 9
The common number is = 6
The common number is = 6

[code]....

How can I do that?

View 3 Replies View Related

C++ :: How To Count Sentences In A Paragraph

Oct 2, 2013

a sample program using c language on how to count sentences in a paragraph...

View 3 Replies View Related

C++ :: Count Backward From 100 To 1 In Increments Of 10

Nov 5, 2014

The question is Create a counting program that counts backward from 100 to 1 in increments of 10.

#include <iostream>
using namespace std;
int main() {
int num = 1;
while (num<100) {

[Code] ....

It seems there are some errors.

View 1 Replies View Related

C++ :: Letter Frequency Count

Nov 13, 2013

I am new to c++. I am writing a program that reads in a text file and gives a count of how many times each letter appeared in the file. I got it to read the text file and do the letter count. B

X = 102
Y = 126
Z = 165
etc...

THAT IS WORNG

The sample output should be
E = 165
T = 126
A = 102
O = 93
etc...

I got it to sort from lowest to highest for the frequency, but cant seem to get the appropriate letter assigned to it.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

[code].....

View 1 Replies View Related

C++ :: How To Count Same Numbers Once In Array

Jan 22, 2015

iam trying to count the same numbers in an array just once like

38
38
40
38
40
37

the output should be 2 since 38 is repeated and 40 too but for my code the output is 3 thats an example of how it should be in a nutshell i want same number to be counted just once in the whole array

and here's my code :

#include <iostream>
using namespace std;
int main(){

[Code].....

View 11 Replies View Related

C++ :: Count The Numbers Below The Average

Mar 7, 2013

I have loaded and 1d array from a .dat file, calculated the average of all the numbers. Now I need to count every number in the array that is below the average and cout that number. This is the method in the class I have so far:

int IntegerArray::countBelowAverage(int numBelowAvg) {
avg=IntegerArray::getAvg();
for(int ct=0; ct<avg; ++ct) {
numBelowAvg=ct;
}
return numBelowAvg;
}

My output from this is always 0 and I know that there are numbers below the avg.

View 2 Replies View Related

C++ :: Program That Can Count Space?

Jun 8, 2013

I was coding a program that can count space, new_line, and other characters in a paragraph, but it doesn't work.

#include <stdio.h>
int main(void)
{

[Code].....

View 1 Replies View Related

C++ :: Reference Count Of Object?

Jun 24, 2014

I have a question regarding reference count of an object. How i'll be able to know that how many pointers are pointing to my object.....

View 3 Replies View Related

C++ :: How To Put 2 Letters Together And Make Them To Count As 1

Mar 11, 2013

how to put 2 letters together and make them to count as 1?

provided that they must consecutive

for example:

p : count as 0
pxp : count as 0
pp : count as 1
xpxp: count as 0
ppxpp : count as 2

View 1 Replies View Related

C/C++ :: How To Count Values In Struct

Nov 6, 2014

I want to count values in a struct.

typedef struct {
  int x;
  int test;
}TYPE_TEST;  
TYPE_TEST My[6] ={
    {16, 50},
    {4,  51},
    {50, 52},
    {47, 53},
    {10, 54},
    {19, 55}
};

int Newbuffer[ ????? ]  

Now I want to make the size of Newbuffer the sum of all "x", that is 146. Not the size of X.

But how to sum all "x".

View 5 Replies View Related

C :: Append Integer To Char As A Count

Apr 15, 2014

I am trying to keep a count on a variable name stored within a structure as char*'s. They are of the same field and I do not know how many there will be so I would like to keep a standard name and append the count.

So say I have a variable name such as "desk", but as I have many of these said desks so I would like to call them "desk1", "desk2", "desk3" and so forth. Any recommendations on how I could do this?

Also since this is somewhat relevant is there an easy way to convert from an integer to a string, something that would work like atoi() in reverse? I wouldn't mind writing a method to do so myself but haven't a clue as to how.

View 5 Replies View Related

C :: How To Count Lines In Dat File Using Fscanf

Sep 15, 2013

I need a way to count lines in a .dat file using fscanf. I must use a regex to check that the characters in the file are alphanumeric. In essence I need to count the ' ' character. I know fscanf ignores this character. I need to exit if it detects anything other than alphanumeric with the digit that is "problem" along with the line number. My .dat file is:

Code:
howard jim dave
joe
(
Maggie My fileCheck.c is: Code: #include "main.h"
int fileCheck(FILE *fp)
{
int ret_val;
int line_count = 0;
char file[BUFF];

[Code]...

The output I am getting is:

Code:
file opened Digit: ( is not an alphanumeric character on line: 5 Program will exit! File closed As you can see, the character "(" is not on the 5th line but the 3rd. It is the 5th "string."

I also wanted to show the regex I am using.

Code:
#define to_find "^[a-zA-Z0-9]+$"

How this can be accomplished?

View 5 Replies View Related

C++ :: How To Count Repeated Numbers In Array

Jan 30, 2015

So I already gave this a go and will post my code below. The question is about the last loop before the program cout's. i thought the count would keep track of the repeated numbers so i could display them but it does not. I italicized the loop i am referring to. or at least i tried to xD

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int inputs[30];
int numofloops;
int maxvalue = inputs[0];

[Code]...

View 1 Replies View Related

C++ ::  how To Count Rows And Columns From File

Sep 2, 2014

So I made a text file which goes like this

word word word word
word word word word word word word
word word word word word
word word word word

(word is actually word I just didnt type them)

Now i figured out how to get the rows to work

#include <iostream>
#include <fstream>
#include <istream>
#include <stdio.h>
int main()
{
FILE* fp;
int countLines = 1;
int i;

[Code]...

I cant figure out column to work... Is it the same method cause im getting confused a lot!

View 12 Replies View Related

C++ :: Count Characters / Vowels And Consonants

Jul 14, 2014

In this assignment, you must enter a file and get out of it this:

Summary
Total characters: 8282
Vowels: 2418
Consonants: 3970
Letters: 6388
Digits: 174
Left parentheses: 17
Right parentheses: 17
Single quotes: 17
Double quotes: 14
Other: 1655

Here is my code:

#include <iostream>
#include <fstream>
#include <cctype>
using namespace std;

char ch;
bool isVowel (char);

[Code] .....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved