C++ :: Looping Activity - Program That Accepts Positive Integer

Aug 10, 2014

You pros are once newbies like us. Hoped you might take a little time sharing your expertise. Got freaked out when our teacher gave us this activity, where she haven't taught this to us yet. So this is the activity (LOOPING) :

Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.

OUTPUT must be:

n = 5
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0

if n = 6
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0
6==5==4==3==2==1==0

View 5 Replies


ADVERTISEMENT

C :: Program That Receives One Positive Integer And Display

Dec 28, 2013

Constructing this right aligned half pyramid? The code I had so far is right aligned and they're not in numbers

Write a program that receives one positive integer and display

_________ _ 1
________ 4 2
_______9 6 3
___16 12 8 4
25 20 15 10 5

when the user key in 5.PS: ignore the line

View 3 Replies View Related

C++ :: Program That Accept Positive Integer - Use Do While To Allow User To Continue Or Not

Aug 10, 2014

So this is the activity (LOOPING) :

Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.

OUTPUT must be:

n = 5
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0

if n = 6
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0
6==5==4==3==2==1==0

View 2 Replies View Related

C++ :: Function That Accepts Integer And Returns A String?

May 5, 2014

How to go about making a function that accepts an integer and returns a string with any one of 5 strings containing the name of the object. For example object number 3 might be "Pen". Object 4 might be "Paper".

To do this would I just use an array?

View 4 Replies View Related

C++ :: How To Extract Positive Integer From Unsigned Char Array

Jan 13, 2015

I have an embedded microcontroller system communicating with a similar system by radio. The api for the radio requires data to be transmitted as an unsigned char array. It will always transmit a positive integer in the range 0 to 255.When I receive the data I am having difficult in extracting this positive integer.

Code:
unsigned char rxData[4]={'1','2','3',''};
int inVal=0;

//want to assign inVal whatever number was transmitted

E.g. 123

I've been at this for a week and have tried at least 10 different approaches including the use of the atoi(), copying the absolute value of each element of rxData into another char array, reinterpret_cast, and others.

View 13 Replies View Related

C++ :: Ask User For A Positive Integer Value And Then Prints Out All Perfect Numbers

Sep 17, 2013

Write a program asks the user for a positive integer value and then prints out all perfect numbers from 1 to that positive integer. I have been trying for some time, i found a way to check if its a perfect number or not but could not find a way to prints out all perfect numbers from 1 to that positive integer. I am here so far.

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int n,i=1,sum=0;
cout<<"Enter a number: ";

[Code] ....

View 4 Replies View Related

C++ :: Create Appropriate Word Form Of Any Positive Integer Up To 999999

Feb 17, 2013

My question is are there various ways that I can approach this program. I.e. do I have to use switch statements?

/*
NumToTxt
Creates the appropriate word form of any positive integer up to 999999
*/

#include <iostream>
using namespace std;
//represents the largest array size for the user entered number
const int MAXNUMARRAY = 6;
/*represents the largest number that can be entered + 1. Used to calculate the first number used to truncate the user
entered number and to display an error message to the user that tells the user the largest number that the program will
accept. */
const int BIGGESTNUMBER = 1000000;

[Code] .....

View 1 Replies View Related

C++ :: Convert Positive Integer Into Its English Name Equivalent To Digit?

Jul 13, 2014

convert a positive integer code into its english name equivalent for digit. A valid code is of size between four (4) to six (6) digits inclusive. A zero is not allowed in the code.

example : if the input is 234056 the output is : INVALID CODE (PRESENCE OF ZERO)
if the input is 23456 the output is : TWO THREE FOUR FIVE SIX
if the input is 9349 the output is : NINE THREE FOUR NINE
if the input is 245 the output is : INVALID CODE (3 DIGITS)
if the input is 2344567 the output is : INVALID CODE (7 DIGITS)

step 1 : input code
step 2 : count the number of digits in the code
step 3 : if there is a zero in the code, "INVALID CODE (PRESENCE OF ZERO)" go to step 4
step 4 : if number of digits is mode or equal than 4 and less or equal than 6, go to step 5 else display the following message "INVALID CODE (<number of digits> DIGITS)
step 5 : call a function called digit_name to convert each digit into its
equivalent english name. display the result
step 6 : print the digits in reverse order
eg; if input is 13453, reverse order is 35431

View 8 Replies View Related

C++ :: Program That Accepts Array Of Characters

Nov 18, 2014

Here's the question: Create a program that accepts an array of characters. And displays the converted array of characters into Upper case if it is given in Lowercase and vice versa. Don't use string, but char.

Example: mychar ="I am A conQUeror."
Code: //My Codes:
#include <iostream>
#include <conio.h>
using namespace std;
int main()

[Code] ....

View 5 Replies View Related

C :: Program That Accepts First / Last Name And Displays It Through Another Function

Sep 25, 2014

I was trying to code a program that accepts your first name and then last name and then displays it through another function. I have checked that the assignments are between similar type of variables and pointers, but I don't seem to get it right.

When first input is taken and then second one, the first one's value changes to same as the second. E.G if first name is L and second name is S and after second input both variables, first and sec, become equal to S. Why?

Code:

#include <stdio.h>
#include <stdlib.h>
//FUNCTION PROTOTYPES
char *input(void);
void show(char *f,char *s);

[code]....

View 7 Replies View Related

C++ :: Program That Accepts Two Input From User?

Dec 8, 2013

I built a program that accepts two input from the user, using a array inside a loop, it is pass to a function inside a class which will display the two number, the problem is when the user is inputting a number and it is 1 the program continuously as the user to input a number, and when 2 is entered the program ask another number and end, but for example you entered 2 and 3. . . it will then outpu 2 and 4 (so 3 + 1 ) and always the last number is plus one. here is the code.

main.cpp
#include <iostream>
#include "newclass.h"
using namespace std;

[Code].....

View 5 Replies View Related

C :: Design Algorithm Using Flowchart Or Pseudo Code To Prompt User For Series Of Positive Integer Value

Oct 26, 2014

Design an algorithm using flowchart or pseudo-code to prompt the user for a series of positive integer values. Calculate the average of these values and display the average at the end of the program. Assume that the user types the sentinel value -1 to indicate end of data entry.

Sample input-output:
Enter a positive integer (-1 to end) : 5
Enter a positive integer (-1 to end) : 7
Enter a positive integer (-1 to end) : 6
Enter a positive integer (-1 to end) : -1

The average value is: 6

I searched online and found out this solution however it is only for three numbers.Is there any way of modifying this to include the sum of x numbers / number of x(integers) to find the average?

View 5 Replies View Related

C++ :: How To Modify A Program So That It Accepts Columns Instead Of Rows

Feb 4, 2015

I have a N queens (actually 8 queens to be specific) program that accepts the numbers in order by row. I need to get it so it accepts the numbers in order by column. At first glance I thought it was just one space different, but it turned out not to be and how to get the one space difference in there. My current code (which I'm aware isn't doing the column accepting right) is:

Code:

#include <iostream>
using namespace std;
int main() {
int board[8];
cout << "Enter the columns containing queens, in order by column: ";
for(int i = 0; i < 8; ++i) {
cin >> board[i];

[Code]...

What the output should be:

Code:

Enter the rows containing queens, in order by column:

7
6
5
3
4
2
1
0

.......Q
......Q.
.....Q..
...Q....
....Q...
..Q.....
.Q......
Q.......

What it is:

Code:

Enter the columns containing queens, in order by column:

7
6
5
3
4
2
1
0
........Q
.......Q.
......Q..
....Q....
.....Q...
...Q.....
..Q......
.Q.......

View 5 Replies View Related

C/C++ :: Program That Accepts Information And Calculated CGPA

Jan 30, 2015

i want to display the grade report of two students in the table but this code will repeat the grade report of one student in the tables and what is wrong with this code below ?

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

[Code]....

View 3 Replies View Related

C++ :: Program That Accepts Three Images And Combines Them Into Panoramic View

Aug 15, 2013

I've been tasked with righting a program that accepts three images and combines them into a panoramic view I'm having trouble getting started?

View 2 Replies View Related

C++ :: Program Keeps Looping Infinitely

May 21, 2014

Why this program keeps looping infinitely when i run it and try to put some input...

#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
using namespace std;
struct Account {

[Code] ....

View 1 Replies View Related

C++ :: Create A Program Using Nested Looping?

Nov 5, 2013

You are to create a program using nested looping. Your program is to have a menu asking the user to select which pattern to create and how many rows to use (it should accept 1 to 10 rows and keep the aspect ratio of the pattern). The patterns are 1 - Box, 2 - V, 3 - Inverted V. Note, if I select pattern 1 with 10 rows, the box will have 10 asterisks in the first row.

Okay so i came up with the box but i have been getting stuck at getting the V or inverted V.

View 1 Replies View Related

C :: Program For Infinitely Looping After And Testing For Active Process

Mar 23, 2013

What I have: A basic program for infinitely looping after and testing for an active process. It has a delay system built in to make it so it is not constantly iterating.

What I need: A way to get process IDs from other Processes other than my program. With a way to use that ID to detect if that process is active on the computer or not.

Parts of my code that need changing:

/* Code for handling the process would go here */

/* Code for detecting the target would go here */

What the goal of my program is: Perform operations to terminate the process of cmd.exe when it is active on the user's computer. Then output the status of the process and the time it took to find that process to the user.

It contained functions that I needed, but I need more information on how to apply them to other processes instead of the parent of my program and its' children.

Here is the code I prewrote for this so far:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ZERO 0
#define INFINITE 1000000000000000

[Code] .....

View 1 Replies View Related

C :: Why Program Can't Subtract Negative Number From Positive One

Feb 2, 2015

My program uses a while loop to eventually get to an error of zero and a root of sqrt(3). I'm not understand why after the third iteration the program fails to compute a new x value. I'm using Visual Studio 2013. The code tag instructions were dubious.

Code:

#include <stdio.h>
#include <math.h>
main() {
/*This program uses the Newton-Raphson method to solve y = (x^3)-3 for it's roots.*/
printf("This program uses the Newton-Raphson method to solve y = (x^3)-3 for it's roots. Enter your estimate of the root.
");
float x,y,z;
int num;
num = 0;

[Code]...

View 1 Replies View Related

C :: Entering Two Positive Integers To Multiply Together - Program Won't Compile

Aug 24, 2013

I'm trying to get my C program to compile but it's not working at all. I've programmed a little in C++ before but I'm not used to C. Here's my program so far:

Code:
int main(void){
// Establishes variables
int num1, num2, product;
float quotient;

[Code] .....

It keeps giving me an error message as follows:

"/usr/bin/ldrelabwk2: file format not recognized; treating as linker script
/usr/bin/ldrelabwk2:1: syntax error
collect2: ld returned 1 exit status"

View 11 Replies View Related

C++ :: Calculate Average Of A Stream Of Positive Numbers - Loop Program?

Feb 25, 2013

Write a program that calculates the average of a stream of positive numbers. The user can enter as many positive numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, treat zero as a positive number, i.e., zero counts as a number that goes into the average. Of course, the negative number should not be part of the average. You must use a function to read in the numbers, keep track of the running sum and count, compute the average, and return the average to the main() function. Note that you must use a loop to do this, as you don't know how many numbers the user will enter ahead of time. I am having problem writing a loop program for it..

View 1 Replies View Related

C :: Program To Show Highest Negative And Lowest Positive Temperature Of Year

Jan 19, 2014

I have an assigment and I don't know yet how to write this program :" I introduce the average monthly temperatures of a year(12 values for 12 months). When I compile the program it needs to show the highest negative temparature and the lowest positive temperature of that year.

Example: Entry data: -4 -6 0 5 10 20 24 25 17 8 -1 -7 exit data : max negative= -1 and min positive= 5 "

View 11 Replies View Related

C :: Create A Proper Table That Accepts Value In Each Box It Contains

Sep 29, 2013

I want to create a proper visible table with boundaries that contains boxes and each box receives a value .I don't know where to start from.i have an idea of using matrix for entering values in each box of table,but how to create lines and boundaries ?

View 1 Replies View Related

C++ :: Add Constructor That Accepts One Argument And Uses It To Set Radius

Apr 10, 2013

I'm getting a error on my Circle::Circle(double radiusValue) constructor. My instructions is 'Add a constructor that accepts one argument and uses it to set the radius.'

#include <iostream>
#include <cmath>
using namespace std;
class Circle {
private:
double x;
double y;
double radius;

[Code] .....

View 3 Replies View Related

C++ :: Function That Accepts Array Of Integers And Its Size As Arguments

Feb 12, 2014

Write a function that accepts an array of integers and its size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth.

The function should return a pointer to the new array. Use ONLY pointer parameters instead of arrays in both functions; use pointers (not subscripts) to move through elements of both arrays. Before calling the function, display your original array. When the function call is completed, display the new array.

Here is what i got so far:

#include <iostream>
using namespace std;
int *shifted (int * , int);
const int SIZE = 10;
int main () {
int array_size [30];

[Code] ....

View 1 Replies View Related

C++ :: Write A Template That Accepts Argument And Returns Its Absolute Value

Nov 19, 2014

Write a template that accepts an argument and returns its absolute value. The absolute entered by the user, then return the total. The argument sent into the function should be the number of values the function is to read. Test the template in a simple driver program that sends values of various types as arguments and displays the results.

#include <iostream>
using namespace std;
template <class integertemplate>
integertemplate totalint (integertemplate integers) {
cout << "How many integer values do you wish to total? ";
cin >> integers;

[Code] .....

View 8 Replies View Related







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