C++ :: Divide User Input By 2 Until 1

Nov 10, 2014

I need to make a program that takes in a user’s number and keep dividing it by 2 until it is 1.I need to display the division steps ...

I do not know how to keep making it divide by 2 until 1. I tired this but it obviously did not work..

Code:
#include <iostream>
using namespace std;
int main() {
//User Input
int input,total;
cout <<"Enter A Number To Be Divided By 2 Until 1" << endl << endl;

[Code] ....

View 7 Replies


ADVERTISEMENT

C++ :: Calculate GPA - Divide Depending On How Many Times User Inputs A Value

Feb 27, 2014

For example, to calculate GPA, we add all the grade point of a course and divide by the number of courses we are taking. How do I create a program in such a way that when the user enters grade point for two courses, it will add the grade points for the two course and divide by 2. And if another user enters grade points for six courses, it adds the grade points and divides by 6.

View 2 Replies View Related

C++ :: User Array Size And Sorting User Input

Nov 1, 2014

I am making program that allows the user to determine how big the array size will be and then asks the user to make up numbers to fill the array. Every time run the program on Dev C++ it says "program has stopped working"

Heres My Code:

//Assignment 19 Program 2
#include <iostream>
using namespace std;
int main()

[Code].....

View 3 Replies View Related

C :: How To See Divide Error

Sep 22, 2013

i was suppose to write a program that gives a divide error but output is not showing anything like it.I am using orwell devc++ 5.4.2 and all the default built tools(gcc compiler etc.) with default settings.so, what should i do to see this error?

Code:

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
float x;
}

[code]....

View 9 Replies View Related

C++ :: Divide By Two Then Add All The Quotients

Mar 13, 2013

I need to write a program that accepts a number from the user, divides that number by two until it reaches one or cannot be divided evenly anymore, then adds all of the quotients from each division and displays them.

So something like this should be displayed:

Please enter a number: 8

8/2=4
4/2=2
2/2=1
4+2+1= 7

I thought about using an array to possibly store the quotients but I just can't see how that would work.

View 5 Replies View Related

C++ :: What Is Symbol For Divide

Jan 25, 2013

Whats the symbol for divide In C++

View 10 Replies View Related

C :: How To Divide / Multiply Two Variables

Feb 26, 2013

I am new to C programming and I am just wondering how to multiply / divide two different variables which the user type in as the promt is asking like this:

Code:
void inmatning3 (double *a, double *b) {
printf("Mata in tv217 stycken flyttal: "); /* asks you to type in 2 numbers */
scanf("%lf %lf", a, b);
}

When you've enterd the two numbers I need to eather multiply or divide the two variables "a" & "b" .....

View 5 Replies View Related

C :: Divide A String Into Triplet?

Feb 12, 2014

Code:

#include <stdio.h> Code: #include <string.h>
int main() {
int i;

[Code]....

need to make triplet for the output

View 11 Replies View Related

C :: Divide Number Until It Reaches To Zero?

Jan 20, 2014

Code where the user wants to divide a number until it reaches to zero?

View 5 Replies View Related

C++ :: Divide And Conquer Algorithm

Feb 6, 2013

I've been stuck on a divide a conquer algorithm problem for about an hour now, and I'm not sure how to solve it. I need to use divide-and-conquer to implement an algorithm that finds the dominant element of an array of positive integers and returns -1 if the array does not have a dominant element (a dominant element is one that occurs in more than half the elements of a given array).

No sorting may be used, and the only comparison that may be used is a test for equality.

I understand the general process I need to follow to solve this problem, but I'm not sure exactly how to convert my thoughts to code. I know that if a number x is the dominant element of an array A, the x must be the dominant element in either the first half of A, the second half of A, or both.

Here is what I have so far.

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int find_dominant(int *A, int p, int r) {

[Code] ....

The program must run in O(n log n) time.

View 2 Replies View Related

C++ :: Program That Add And Divide Two Numbers

Mar 20, 2013

I'm practicing so I wrote this simple program that suppose to add and divide two numbers. It does that but the result comes out with a 0 at the front and don't know why.

#include<iostream>
using namespace std;
int main()
{
int a ,b;
int result;
a = 0;
b = 0;

[Code]...

View 4 Replies View Related

C :: Divide And Conquer Find Min And Max By Recursive

Mar 6, 2015

In this code nothing modify except function minMaxSearchRecursive

Code:
int min(int a, int b) {
if (a < b) {
return a;
} else {
return b;

[Code] .......

View 9 Replies View Related

C++ :: Divide Array Into Multiple Arrays

Jan 16, 2015

I am trying to do this:

Read a text file which is like:

2
2 10 1 2 7
3 8 3 7 7 10 7

The first line indicates how many paths exist in my design.
The second and third lines are those lines(the first number indicates 2 pairs, so 10,1 and 2,7 are 2 pairs)
The first element in the third line indicates 3 pairs and the pairs are 8,3 and 7,7 and 10,7.

I have been able to read the text file and store these into ONE array. However, I need to divide them up and have each line in a seperate array.

So for example

array alpha to contain 10,1 and 2,7
array beta to contain 8,3 and 7,7, and 10,7

How would you do this?

View 4 Replies View Related

C/C++ :: How To Multiply And Divide 2 Numeric String

Mar 28, 2014

I want to multiply and divide 2 string that contains number. For example

s1=4 and s2=8 s1*s2=32 ,s2/s1=2

I don't want convert string to integer and do it.because i deal with big numbers.and these should be in string form.

View 1 Replies View Related

C/C++ :: Getting Divide By 0 Error When Using Modulus With Number Below 1

Jan 31, 2013

I am trying to get a remainder of a number with a = 0.9144, rm = ry % a; however, I keep getting a divide by zero error (I believe due to the program rounding 0.9144 down to the integer 0).

View 2 Replies View Related

C/C++ :: Divide A Number By 128 Without Using Division Operator

Mar 8, 2013

Question about instead of using the division operator to display the output of user"s input....

View 4 Replies View Related

C++ :: Second User Name Input Is Being Skipped

Jan 1, 2014

In this simple end-of-chapter problem, the ages of two people are to be compared and determine who's older. The problem I'm experiencing is that the second user name input is being skipped and going straight to the second users age.

So while running the program it looks something like:

What is user ones name?
<input name>
How old are they?
<input age>
What is user twos name?
How old are they?
<input age>
<if statement result>

Here's my code:

Code: #include <iostream>
#include <string>
using namespace std;
int user_one_age;
int user_two_age;
string user_one_name;
string user_two_name;

[code].....

View 9 Replies View Related

C# :: TexBox User Input To Hex Value

Sep 2, 2012

So I've got this form that a user puts in a numeric value into a text box. This value then has to be placed into a byte string of data so that it can be transmitted over as a packet. Bellow is what I have so far:

Code:
Byte[] OUTBuffer = new byte[65];//Allocate output memory buffer
Byte[] INBuffer = new byte[65]; //Allocate input memory buffer

if (setmSpeed == true)
{
OUTBuffer[0] = 0; //Not used, must be set to 0
OUTBuffer[1] = 0x85; //Command mode

[Code] ....

I've put in red the area where I'm having issues. I've tried different methods and have not been able to get this working yet. It only works if I speciffy the value manually as with OUTBuffer[1] = 0x85;, but I want byte 2 of OUTBuffer[] to be set with what I put in the text box.

View 4 Replies View Related

C :: User Input To File

Mar 18, 2013

I'm creating a program that should create a structure of a list of people entered by the user; the only problem I'm having is with the %c. When I have it, the loop only occurs once; if I put a %s, the loop occurs up to 25 times, but it doesn't write to the text file. Here is the code:

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
[code]....

View 2 Replies View Related

C :: User Input With Forks

Apr 7, 2013

So im working with forks and creating 2 fork processes. One child and parent. What im trying to get the child to ask me for a value. Then the parent would start to figure out the value and keep trying. Once it figures it out its tells them you got it and simply stops the program. I cant seem to get the program to keep guessing and stop when the number is found which sends a sigint. Here's what i have so far.

Code:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdbool.h>

int main() {
int j, i,pid;

[Code] .....

View 2 Replies View Related

C++ :: Alter User Input

Feb 6, 2013

I have this code here that counts the number of alphabetic letters the user's input,the number of characters total, the number of words and the number of "the" that was used. However now I need to alter the user's input to have two spaces after the end of each period, no spaces between a word or comma and each sentence has to have a capitalized letter and display them at the end. And I'm stuck on the altering part. I briefly started the 2 spaces after each period but it won't display anything.

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

[code]....

View 7 Replies View Related

C++ :: Trying To Get User Input Into Array

Apr 25, 2014

I have written a program and i had to pass an array into a function and now i have a variable for the subscript of the array and i was the user to input data, specificlly a string, more specifically first and last name without having to create two arrays, i have to do this with other things in the program as well, here is part of the program:

int addFunc(const int totNum, string city[],string state[],string street[],string name[],
int addNum[],int zip[],int telNum[],double bal[],int dateLp[], int addCount, int accNum, int usNum)//function will add a new account {
int countAf = 1;
if (usNum < 20)

[Code] ....

it should be able to take firstname space lastname

View 5 Replies View Related

C++ :: Cin Not Waiting For User Input

Apr 21, 2013

since around 2hours im really fighting with the cin command.It doesn't matter what exactly im trying, it's just not waiting for user input and keeps directly using 0 as "entered" value.

int Value;
cout << "Enter a new value: " << endl;
cin >> Value;
cout << "The value has been set to: " << Value;

View 4 Replies View Related

C++ :: CMD Closes After User Input

Jun 7, 2014

I'm trying to make a simple program that accepts user input, simple stuff. When the user (me) enters a number to be sent to the console and i press enter so it accepts the data, it closes the command prompt and thus ending the program. I just need to find a key that i can use to continue but doesn't close cmd.

View 5 Replies View Related

C++ :: How To Tell Whether User Input Has Already Been Used In 2D Array

Mar 7, 2014

My parameters are that the users input has to be from 1 to 9 and the same number can't be entered twice. How do i modify this code to make sure that the user did those things or an error message should appear that their input is invalid.

#include <iostream>
using namespace std;
int main() {
int square[3][3];

[Code] ......

View 6 Replies View Related

C++ :: User Input In Italics

Oct 10, 2014

I am a beginner in C++. The program I want to create is as follows. The program will take a sentence as input from the user in italics and display it.

The output will be:
Enter a sentence :
Hello World!
You have entered : Hello World!

How to take user input in italics.

View 6 Replies View Related







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