C++ :: Input Number And Print Out Same With Stars In Between

Apr 16, 2013

Basically i want to input a number for example 123456 and get back how many 7's are in the input number and also to print out that same number with stars in between like this *1*2*3*4*5*6*. Here is what i have so far:

#include <iostream>
using namespace std;
int countSeven(int x){
if(x == 7)return 1;
int c = 0;
while(x/10 > 9)c++;
return countSeven(x/10)+1;

when i compile it does not do what i tell it it just tells me there are 0 7's in the input number no matter how many there really are...

View 9 Replies


ADVERTISEMENT

C++ :: Print Stars Function In 1D Array?

May 2, 2014

I'm having trouble with my for loop near the end of the program was able to print everything else.

Sample Output:

*** end of 27610_Arrays04.cpp program ***

City City Points
--------------- 1---5----10---15---20
Belvidere **********
Freeport ********
Byron ************
Stillman Valley ***************
Rockford *********

*** end of 27610_Arrays04.cpp program ***

Input:

TODO #1: complete the coding of the points array
An integer array of 5 numbers: 10, 8, 12, 15, 9

TODO #2: complete the coding of the cities string array
An string of 5 city names intialized to:
"Belvidere", "Freeport", "Byron", "Stillman Valley", "Rockford"

Compile-time arrays with initialization lists.

Processing & Output:

TODO #3: complete the coding of the call to the printStars() function

TODO #4: code the printStars() function

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main(void) {
/* declarations ------------------------------------------------*/

[Code] ....

View 2 Replies View Related

C++ :: Print Out Square Of Stars With Different Length And Width Given?

Feb 27, 2013

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

[Code].....

how do i change this code to accept two numbers from the user and print it as the different length and widtth? it has to be a for loop as well.[code]

View 5 Replies View Related

C++ ::  Vertical Histogram - Variables In For Loop To Print Stars

Dec 6, 2013

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

[Code] .....

View 4 Replies View Related

C++ :: Print Stars Function - Corresponding To Array Index Size

Nov 24, 2014

I am having trouble getting the stars to output correctly in the printStars function. the final output should look something like this:

#include <iostream>
using namespace std;
int readArray(int input[], int size);
void printArray(int input[], int count);
void printStars(int input[], int size);

[Code] ...

View 3 Replies View Related

C :: Take User Input Between 1 And 10 And Print Out Number As A Word

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

C/C++ :: Using Print Statement To Print Certain Number Of Spaces

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

C :: Program That Allow User To Enter A Number N And Print Nth Prime Number

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

C :: How To Reserved Int Number And Print As Float Number

Nov 24, 2013

How to reserved int number and print as float number ?

View 1 Replies View Related

C++ :: Pyramid Of Stars With Spaces

Mar 21, 2013

How to solve this (for cycle)?

View 12 Replies View Related

C++ :: Input Decimal Number And Output To Be Number Scientific Notation

Apr 26, 2013

I need to write a code in c++ , to input decimal number and the output to be number in Scientific notation with 32 bits .

View 1 Replies View Related

C++ :: Find Next Palindrome Number Larger Than Input Number

Nov 14, 2014

Q. WAP to find the next palindrome number larger than the input number.

for eg:-

Input=25
Output=33

The program is giving correct output for number with all digits '9';

why is it not giving output.

#include<iostream>
#include<string>
using namespace std;
int main() {
int len,flag=1,count=0,num,ind;

[code]....

View 8 Replies View Related

C++ :: Star Pyramid Program - Adding Stars?

Sep 13, 2013

I have written a star pyramid program, it adds two stars at a time but I want to rewrite the program so the stars double each time.

#include<iostream>
using namespace std;
int main() {
int a = 0, b = 8;
for (int c = 1; c < 10; c++) {
for (int space = b; space > 0; space--)

[Code] ...

View 1 Replies View Related

C++ :: Print Out All Input Values

Mar 16, 2013

I have a problem with how to print out all the numbers that the user enters the code looks like this so far:

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

[Code] ....

I want the program to print out all the numbers that the user has entered after the program have said the higest and lowest number is ?. But I do not know how to do this I thought it could be something like this:

Code:
cout << input[0];
//or
cout << input[i];
/*

Because i is the number of how many enters of numbers the user can do*/ But that was totally wrong tried to do another "for loop" in the first for loop but that was meaningless because it can't change anything in the first "for loop".

View 7 Replies View Related

C++ :: Read From Input And Print It Out

Jan 31, 2013

I am trying to read from this input and print it out to stdout:

#include <cstdio>
FILE* InputFile;
//struct CityBlock
//{
// bool Blocked;
// bool N_Blocked;
// bool FireStation;

[Code] .....

It outputs whole lot of nonsense snippet:
8?/usr/lib/libSystem.B.dylib&X)`!jH??H???H?H?u??????
H?H???H?H?9u?H??<????????UH??H??H?}?H?H???wH??]???
UH??H?? ?}?H?u??E???H??H???l?H??E???????H??H?????????
????M?M??u?H?gH????E??E?E?E?H?? ]ÐUH??????lj??

View 4 Replies View Related

C/C++ :: Print Out User Input

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

C++ :: Construct A Program Without Main Function That Output Stars

Nov 5, 2013

I am trying to construct a program without a main function that outputs stars but at the same time outputs the number and a colon after the number but before the number of star. This is the coding i have so far.

void output_stars(int num){
if (num > 0){
cout << "*";
output_stars(num-1)

[Code] ....

The program is working the way it should i just can't figure out how to output the number and a colon. The main function is written as such:

output_stars(1);
output_stars(2);
output_stars(5);
output_stars(3);
output_stars(4);
output_stars(7);

How to get the numbers of the main function to show up with the stars of the previous function.

View 6 Replies View Related

C++ :: Input Three Names And Print Each One At Different Line

Dec 10, 2014

We need a program that takes three names ( first middle last ) and print it each one at a different line...

View 5 Replies View Related

C++ :: How To Print Out Second MIN And MAX Number Without Using Array

Oct 13, 2014

How can i print out the SECOND MIN number and MAX number without using array?

cout << "Please input a positive integer: ";
cin >> input;
min = input, max = input, secondmin = input;
do {
cout << "Please input a positive integer: ";
cin >> input;

[Code] .....

View 7 Replies View Related

C/C++ :: Have To Identify Odd Number And Print Them

Apr 10, 2013

#include<stdio.h>
#define TRUE 1  
int formOddInt(int n);  

[Code]....

View 5 Replies View Related

C++ :: Print Last Digit Of Number Output Always Become 6?

Oct 26, 2013

i just started learning programming and i just wanna know how come when i try to print the last digit of a number the output always become 6?

View 4 Replies View Related

C :: How To Print Largest Number From 5 Rows

Sep 26, 2013

i want to print Largest number from any 5 rows.Th number printed should be any one of the largest in the five rows of 2d arrays.I have created code for largest number in each row but how to pick and print them randomly?.

Code:

#include<conio.h>
main( )
{
int a,b,c,d,e,x;
int arr[] = {a,b,c,d,e};
int Matrix[5][5] ={ /*Initializing array*/
2,4,3,5,9,
6,8,2,2,10,

[Code]...

View 9 Replies View Related

C :: Print The Inverse Number On Screen

Dec 25, 2014

Print the inverse number. Ex: 2178*4=8712

Write down a program which can satisfy the prerequisite and print out the screen.

The answer is:

Code:
void inverse2 ()
{
int i,j;
for (i=1000;i<=9999;i++)
for (j=1;j<=9;j++)
if (i*j==inverse (i))
printf("%5d%2d",i,j);
}

I can't understand the double for loop.

for (i=1000;i<=9999;i++)
for (j=1;j<=9;j++)

And The meaning for

i*j==inverse (i)

View 2 Replies View Related

C :: Can't Print Number Stored In Array

Jan 12, 2015

when i compile and run it it gives me the number 0 and not the proper number stored in array.

Code:

#include <stdio.h>
int main()
{
int myArray[11] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
}

[code]....

View 4 Replies View Related

C++ :: Check If A Number Is Odd Or Even And Print It To The Screen

Mar 8, 2013

My objective is to check to see if a number is odd or even and print it to the screen just to make sure its working correctly.

The data file contains:
138
402 2 485
9
43
98 805
58
421
948 7 97
48
67
35
42
948
579 39 12
700 20 500 210
98

I can get the numbers to print fine using:

fstream infile1(argv[1]);
if(!infile1.is_open())
cout << "Could not open file";
else {
char listNum;
while(infile1.get(listNum))
cout << listNum;
}

However, when I check for odd or even numbers it will check each and every number.

printed like this (partial list):
1 is odd 3 is odd 8 is even
9 is odd

But it should print:
138 is even
9 is odd

I tried using getline, but it keeps giving me the errors:
invalid conversion from 'void*' to 'char**'
invalid conversion from 'char' to 'size_t*'
too few arguments to function 'ssize_t getline(char**, size_t*, FILE*)'

Here is the getline code, what am I doing wrong? I have tried switching things around, adding things. Just nothing works.

ifstream infile1(argv[1]);
if(!infile1.is_open())
cout << "Could not open file";
else {
char listNum;
getline(infile1, listNum);
cout << listNum;
}

View 2 Replies View Related

C++ :: Rational Number Does Not Print As Reduced

Apr 10, 2013

The program works, but the rational number doesn't print as reduced. I guess i have to call the reduction function, but i'm not sure where

the output that i get is:
2/6 + 7/8 = 58/48
58/48 = 1.20833

2/6 - 7/8 = -26/48
-26/48 = -0.541667

2/6 x 7/8 = 14/48
14/48 = 0.291667

2/6 / 7/8 = 16/42
16/42 = 0.380952

the output that i suppose to get is:
1/3 + 7/8 = 29/24
29/24 = 1.20833

1/3 - 7/8 = -13/24
-13/24 = -0.541667

1/3 x 7/8 = 7/24
7/24 = 0.291667

1/3 / 7/8 = 8/21
8/21 = 0.380952

here is my header file

//Prevent multiple inclusions of header
#ifndef RATIONAL_H
#define RATIONAL_H
//Rational class definition
class Rational {

[Code] .....

View 3 Replies View Related







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