C++ :: Making Diamond Out Of Asterisks Based On Given Odd Integer Input

Sep 6, 2014

I have been tasked with making a diamond out of asterisks based on a given odd integer input. For some reason the bottom half of my diamond will not print. I'm not sure as to why.

Here is my code:

#include "stdafx.h"
#include <iomanip>
#include <iostream>

using namespace std;
int _tmain(int argc, _TCHAR* argv[]){

[Code] ....

View 2 Replies


ADVERTISEMENT

C/C++ :: Printing Square Pattern Of Asterisks Based On User Input

Dec 15, 2014

I have to make a program that displays a square of asterisks based on the users input. Here is what I have so far.

#include<iostream>
using namespace std;
int main(){
int number;
cout << "Enter a number: ";
cin >> number;
for (int i = 0; i < number; i++){

[Code] ....

But the square needs to be hollow like this. So if the user enters 5 then the following square will be shown.

*****
* *
* *
* *
*****

How to make it do this.

View 11 Replies View Related

C++ :: Print In Asterisks Oval / Arrow And Diamond Using For Loop And If Statements

Jan 15, 2015

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

this is my main functions. I have problem making a program that prints in asterisks an oval, arrow and a diamond using for loop and if statements.

View 1 Replies View Related

C/C++ :: Create A Program That Prints A Certain Number Of Asterisks Based On User Input

Apr 12, 2015

I need to create a program that prints a certain number of asterisks based on user input. The user inputs 5 and I want my program to output "*****". How would I do this in C? I've tried printf("%#**", myvariable) but this does not work it only prints "*".

View 1 Replies View Related

C# :: How To Display Input Number Of Asterisks

Nov 14, 2014

I have been stuck at a dead end,I got it to display a single asterik for an inputted number, but how would i go about in adding that asterik for each number?

my code is the following

int userinput = int.Parse(InputOutput.GetInput("Enter values into array"));
Int32[] inputChoices = new Int32[9];
for (int x = 0; x < inputChoices.Length; x++) {
inputChoices[x] = 0;
} if (userinput == 1)

[Code]...

View 2 Replies View Related

C/C++ :: Converting 8-byte Integer To String Based Integer

Oct 15, 2014

Complete the function myitohex so that its converts 8-byte integer to string based hexadecimals.

Ex: printf("0x%s",myitohex(64,hex)); should printout "0x40" on the screen
char *myitohex(uint8_t i, char *result){
???
return result;
}

I wrote:

#include <stdio.h>
#include <stdint.h>
char *myitohex(uint8_t i, char *result){
*result = i + '0';

[Code] ....

0xp gets printed out which is wrong. I think *result = i + '0'; is wrong. What changes should i do on this row ?

View 4 Replies View Related

C :: Making Integer From Pointer Without A Cast

Dec 15, 2013

Code:
#include <stdio.h>
#include <stdlib.h>
#define CLASS 4
#define STUDENT 11
#define GRADE 5

[Code] ....

Giving me that error on 75:10
avesub+=grade[k];
and 90:17
donkeypunch+=grade[j][k];

not sure exactly why

View 8 Replies View Related

C++ :: Converting Integer To String Based On Digits

Apr 23, 2013

I want to convert the integer into a string.

int x = 693;
char chararr[max];

In my homework, x is unknown. but don't worry, I wont ask for the full code. I just need the part where you change the int into a string/array of char.

I'm thinking in circles from where to start?

View 2 Replies View Related

C++ :: Sorting Vectors Based On Value Of First Integer In Ascending Order

Feb 13, 2013

I have a vector which contains vectors containing 7 integers each. I'd like to sort these vectors based on the value of the first integer (int IOT), in ascending order. I know this type of question can be found everywhere, but I'm lost as to why this doesn't compile.

#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <windows.h>
using namespace std;
class orders {
public:
int IOT; // Incoming Order Time

[Code] ....

View 7 Replies View Related

C/C++ :: Print Pascal Triangle Based On Integer N Inputted

Nov 7, 2014

void Pascal(int n){
int i,j;
int a[100], b[100];
a[0]= 1;

[Code] ....

I've been trying to make a function that prints a pascal triangle based on an integer n inputted.

View 3 Replies View Related

C/C++ :: Making A Date Format Input?

Dec 16, 2014

how my code should work is a console screen in which the user enters a date using format dd/mm/yyyy

Regardless of logical errors (checking days if bigger than 31 or negative values or.. etc) My code should be able to validate the following:

- if the user enters a letter, the program should output an error message

- if the user typed the date as 8/2/2014 the program should convert it to 08/02/2014 without returning an error message

Here's my code so far, I really can't find the bugs in it

#include<iostream>
using namespace std;  
main(){
 char d[2], m[2], y[4], br1, br2, dx, mx;
 bool end, nobr1, nobr2;

[code]....

as you notice, I tried two different validating formats in the days and months, unfortunately they both failed..

Here's how my program is outputting so far:

View 3 Replies View Related

C++ :: Making Function To Read Unsigned Integer Into Variable Of Type Unsigned Short Int

Apr 3, 2014

How can i write a function that will read an "unsigned integer" into a variable of type "unsigned short int"? i can not use cin >> inside the function.. so i am looking for atleast a hint!

View 16 Replies View Related

C :: Nested Loops - Asterisk Diamond

Jul 11, 2013

Getting close but I think I am stuck on the second loop. The input you put in will be doubled (and it's not supposed to).

Code:
int main() {
int n, i, j, k;
printf("What would you like the height to be? (Positive odd integer)
");
scanf("%d", &n);

[Code] .....

View 3 Replies View Related

C++ :: Asterisk Diamond Is Printing Out Wrong

Sep 6, 2014

I feel as if I'm so close and I'm just messing up a value somewhere, but I am at a loss as to what I should change. Here is my code:

#include "stdafx.h"
#include <iomanip>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {

[Code] ....

View 2 Replies View Related

C++ :: Drawing A Rectangle And Diamond Using Recursion?

Oct 23, 2013

write a code that draw a block and diamond each in a single run by using '*' in recursion.

Below are one 10X10 rectangle and 6X4 diamond.

**********
**********
**********
**********
**********
**********
**********
**********
**********
**********

**
* *
* *
* *
* *
* *
* *
* *
**

Note: I couldn't write the diamond here appropriately somehow.

View 1 Replies View Related

C++ :: Federal Tax Calculator Based On User Input

Apr 17, 2014

I am doing an assignment that is to calculate the federal tax based on the users input. I am not entirely sure what it is doing, but it is definitely not what I want it to do. I commented out the loops because they seemed to have caused a problem, but there is still problems that are making the program do something else. Here is my code:

#include<iostream>
#include<string>
using namespace std;
double getData();
double taxAmount();

[Code] ....

Functions just seem like they are not my thing. It never gets to the second function to do the calculations and then return to main to display the results.

I tried changing the code to a switch(status) with a default: at the end that looped the "please try again" but for some reason, that was a fail, it created an endless loop.

View 15 Replies View Related

C++ :: Pixelate Image Based On User Input

Dec 24, 2014

My assignment is to pixelate an image based on users input. I have a structure that stores the image, and in this structure I'm storing the height and width and a dynamic array of RGBA struct.

This is my function. my main issue (that I've found) is offsetting and figuring out a way to handle the "edge" if the dimensions don't add up to the set pixelation size.

// @------------- Pixelation X
bool filter_pixelation(float percentageX, float percentageY, Picture& pic) {
// URL
/* 50% of 80 = (50/100) * 80 = 40 */
size_t perX = percentageX * (float)pic.width;
size_t perY = percentageY * (float)pic.height;

[Code] ....

Here is the getIndex function:

int getIndex(int x, int y, int width) {
return y * width + x;
}

View 1 Replies View Related

C/C++ :: Change Data Based On Users Input?

Feb 7, 2014

Player is given choice of x number of Races This choice changes the player's base stats. Then player is given a choice of x number of Classes (archer, warrior, etc.) This choice determines how the player's stats will change upon leveling up.

#include <cmath>
#include <iostream>
#include <ctime>

[Code]....

View 7 Replies View Related

C/C++ :: How To Draw A Square Based On User Input

Nov 5, 2014

Okay so I have to draw a square using "c" that draws according to the user input. Also, this has to be a function, and here is the code I have so far:

#include <stdio.h>
void DrawSquare(int length, char symbol);
void DrawSquare(int length, char symbol) {
int row;
int col;

[Code] .....

When I run this program it compiles fine but when the user input is recorded it just draws nothing but makes tons of spaces.

View 2 Replies View Related

C :: Count How Many Negatives And Positives Are Based On Users Input

Oct 5, 2014

I just don't understand how you would have it count how many negatives and positives there are based on the user's input? Here's the problem and the code it provides:

Modify the program so that is displays the average of the positive and negative numbers. (Hint: be careful not to count the number 0 as a negative number.)

Code:

#include <stdio.h>
#define MAXNUMS 5
int main() {
int i;
float number;
float postotal = 0.0f;
float negtotal = 0.0f;

[Code]...

View 6 Replies View Related

C++ :: How To Stop Outputting Data Based On A User Input

Sep 27, 2013

how to stop outputting data based on a user input. The text file is as follows:

1. a
2. b
3. c

and the code I'm using is as follows:

int main (){
string line;
int search;
cout << "Enter a number from 1-3" << endl;
cin >> search;
search++;
ifstream myfile ("example.txt");

[Code]...

What I want to do is to just output number 1 (the whole line) if the user enters number 1. However, I get an error on the second condition w/c is the "&& line!= search"

View 1 Replies View Related

C++ :: Dynamic Function Execution Based On String Input

Jun 27, 2013

I've got some functions and macros that I want to execute based on a string input that matches the function's name. I came across as this being a possible solution that I'd like to pursue IF it is possible to do. To clarify, I want to be able to look at a string and if the string matches the name of a defined function or macro then it will execute. Is there an effective way to do this (or is it even possible)?

It has to be pretty robust and dynamic given the project's purpose. Basically there's an input file that is being parsed and functions should execute if called upon in the file. I can't simply match strings to their corresponding functions in decision statements, as this isn't robust and isn't scalable.

View 3 Replies View Related

C++ :: Incrementing Values In Vector Based On Variable Input

Mar 24, 2014

I'm trying to increment the values in a vector, not the vector size, based on variable input. Basically I have a vector of size 10, and all of its values are initialized at zero. The program counts the frequency of numbers 0-9 in a four digit user input. This is what I have (I want it to work so badly but the compiler says that I'm using a pointer to a function used in arithmetic):

for (int i=0; i < num_slots; ++i) {
++guess_frequency[guess[i]];
}

I just want to know if you can increment values within a vector:

E.g.
change
0 0 0 0 0 0 0 0 0 0
to
1 0 0 0 2 0 0 1 0 0

View 6 Replies View Related

C++ :: Storing Multiple Arrays Based On User Input

Feb 7, 2014

I'm trying to create a function where it allows the user to type in multiple amounts of integers, so if the user wanted to have 3 different storages that hold different integers, the input would look something like this:

5
97 12 31 2 1 //let's say this is held in variable "a"
1 3 284 3 8 // "b"
2 3 482 3 4 // "c"
2 3 4 2 3 // "d"
99 0 2 3 42 // "e"

Since we don't know what number the user will input every time, I'm not sure how to create a dynamically allocated array that will create an x amount of arrays every time.. I want to be able to access each index of a, b, c, d, e or however many arrays there are.

So far, this is what I have, but I'm having trouble creating the arrays since it's unpredictable. I'm purposely not using vectors because I don't really get how pointers work so I'm trying to play around with it.

int* x;
int length, numbers;
cin >> length;
x = new int[length]
for (int i=0;i<length;i++)
{
cin >> numbers; //this doesn't work because it only grabs the first line for some reason
x[i] = numbers
}

View 3 Replies View Related

C/C++ :: Program That Calculate PI Based On User Input For Accuracy?

May 24, 2014

I am trying to create a program that will calculate pi based on a user input for accuracy. If the user input .3 then when the leibniz infinite sum value at a particular i becomes less then the input of .3 then the loop will exit.

I have looked at a number of examples on the internet but I feel lost. I have put together working code that will infinitely output sums but I need the loop to stop when the sum value is less then the accuracy value.

My question is what is wrong with my while loop, why will it only give me infinite summations? How do I make it so that the loop will exit when my accuracy input is greater then the sum?

int main () {
double accuracy;
cout<<"Give an accurate number." << flush;//looks nice
cin>>accuracy;
int d;//initialize denominator
double pi = 0.0;
while(accuracy < d){

[Code]...

View 8 Replies View Related

C++ :: Display All The Contents Of A File Excluding One Based On User Input

Mar 10, 2014

i want to display all the contents of a file excluding one based on user input say i have 4 records in the file numbered 1 to 4....the user chooses 2 to exclude it outputs records 1,3,4,4 when it should be records 1,3,4 what am i doing wrong here is the code.its basically displaying the last record in the file twice

void excludeRecord()
{
ifstream read;
read.open("Data.txt");
int recordC =0;
string fnameC = " ";
string lnameC = " ";

[Code]...

View 2 Replies View Related







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