C++ :: Program Only Accept Integer From 0-10 But Doesn't Show The Factorial

Feb 28, 2013

#include<iostream>
using namespace std;
int main() {
int a[9],x,f=1;
cout<<"Please enter an integer [0-10 only] : ";

[Code] ....

View 3 Replies


ADVERTISEMENT

Visual C++ :: Program Doesn't Accept Input Values True?

Nov 1, 2014

I am making a program which is going to print out a head image according to the input values entered by the user. Here is the code:

Code:
#include <iostream>
#include <string>
using namespace std;
void Sides()
// draws the sides to take proportion

[Code] .....

At first i tried to work program like:

Code:
cout << "plase enter which way you want to print out the head, with parted hair or bald." << endl;
cin >> headstyle;
if (headstyle != "bald" || headstyle != "parted hair" )

But it also had given the same mistake. The program compiles BUT; even if I put in the values bald or parted hair the program prints out "wrong input" then exits.

View 2 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++ :: When User Inputs It Doesn't Show The Function

Aug 2, 2014

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

[Code]....

i have already tried putting system pause or cin.get after it, but no luck

View 1 Replies View Related

C/C++ :: Getting Prime Factorial Of Integer?

Sep 23, 2013

code of prime factorization. Example input:135 / The problem is I want to be an output of (3^3) (5^1) instead of 3,3,3,5.

here's the code:

#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;  
void get_divisors(int n);  

[code]....

View 3 Replies View Related

C :: Accept Input Number From User And To Convert It Into Array Of Integer

Oct 7, 2014

i was trying to solve a problem in SPOJ and what i wanted to do is to accept an input number from the user and to convert it into a array of integer.

Code:

#include<stdio.h>
int * toarray(int *num);
int main(void)
{
int testCases;
}

[code]....

But whenever i try to print the array in the main function i get only two value and the rest address

Code:

1//number of testCases
23456 //input number
6
2293452
4
2293700
1974439125

Process returned 0 (0x0) execution time : 4.152 s
Press any key to continue. However, if i tried to print the array from within the function, it prints the numbers just fine.

print the array elements from the main program, so that i would be able to go on with the rest of it

View 1 Replies View Related

C++ :: Accept Signed Decimal Integer As Input And Output In Binary

Jan 29, 2015

Write a C++ application program to accept a signed decimal integer as input and output the equivalent 2s complement version in 16-bit binary. Include a space between every four bits in the output string. The input will only be processed by the application if it falls in the valid range that can be represented in 2s complement format with 16 bits. The range of a decimal number from - to + is -32768 to 32767.

View 3 Replies View Related

C/C++ :: Switch Case - Show Integer Between 1 To 1000 As Words

Sep 21, 2014

I'm brand new to coding, and I'm learning C. To start, I wanted to create a program that would show an integer between 1-1000 as words (such as 157=One Hundred and Fifty Seven)

I'm having trouble with the switch-case function. I know that what I'm doing all works until it hits the switch function. I've tried switching one of the strcpy functions out with a printf, followed by a system("PAUSE") function, and it gave me results, so I know that the switch function is accepting my "hund" integer. I believe my problem lies within the strcpy function, and its use in the case function.

In short, why isn't the strcpy function working in the switch-case function? Below is my code as it is:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int num;
int hund;
char letHund[20];

[Code] .....

View 2 Replies View Related

C/C++ :: Factorial Program With Recursion

Nov 9, 2014

I put some checks in factorial program, I am confused how 27, 40 50 is coming in output and ans is 10.

#include<stdio.h>
int fact(int n) {
if(n==1) {
printf("hello1 %d
",n);
return 1;

[code].....

View 2 Replies View Related

C/C++ :: Factorial Program - Input Number

Mar 26, 2014

I'm trying to run a factorial program but I'm getting the error statement has not effect.

here's the code

#include <iostream>
using namespace std;
int main() {
int fac = 0;
int sum = 0;

[Code] ....

the error happened in the int main section

View 3 Replies View Related

C++ :: Accept Integer Array And Its Size As Arguments And Assign Elements Into 2 Dimensional Array

Jan 10, 2015

Write a program using user-defined function which accepts an integer array and its size as arguments and assign the elements into a two dimensional array of integers in the following format: If the array is 1,2,3,4,5,6, the resultant 2D array is

1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0

View 1 Replies View Related

C :: Program To Calculate Factorial Of Numbers - For Loop

Feb 5, 2013

I have been working on a program to calculate the factorial of numbers. Part of my code is copied and modified from the FAQ about validating numbers in user input.

I have encountered a problem with the for loop that I am using near the end of my code. No matter what I do, it seems that my loop only does the multiplication of b = a*(a-1) and then prints. For example, inputting 5 will result in a print of 20, but the factorial is 120.

Code:
int main(void) {
char buf[BUFSIZ];
char *p;
long int a;
long int b;
long int i;

printf ("Enter a number to be factorialized: ");

[Code] ....

View 5 Replies View Related

C++ :: Writing Program That Computes Factorial Of Number And Displays It?

Oct 24, 2014

write a program that computes the factorial of a number and displays it. A factorial of a number (written N!) is defined as N * (N-1) * (N-2) * (N-3) ... *1 In other words, 5! = 5 * 4 * 3 * 2 * 1 = 120 and 3! = 3 * 2 * 1 + 6.

Example of output 15 is 1.30767e+012

Can't get it to display error when user enters a number lower than 2 or higher 60.

// Program to calculate factorial of a number
#include <iostream>
#include <iomanip>

[Code].....

View 13 Replies View Related

C++ :: Create Program That Will Accept 2 Integers?

Sep 4, 2013

how can I create a program that will accept 2 two integers. the user will also choose among the different operations:

1 for addition
2 for subtraction
3 for multiplication
4 for division

View 4 Replies View Related

C++ :: Program That Accept Input For User ID

Oct 28, 2013

I need a program to run that will accept an input for user id. It will take the customer input and capitalize the letters, and return invalid id with the user inputted values. Then if it's valid it will add a counter counting the number of letters and numbers. It will keep track until the user puts in !. It seems when I try to pass values from the array to my toUpper function to capitalize it it doesn't seem to work right.

View 3 Replies View Related

C# :: Program Won't Accept Database Information Using Parameters

Apr 30, 2014

I am creating a WinForm registration application and my program accepts user input information and stores it but I am struggling to use my login function. I believe there is an error in the area of cmd.Parameters.AddWithValue section, I dont think addwithvalue is correct ? I get a fatal crash has occurred when I click Login

string constring = "datasource=127.0.0.1;port=3306;username=root;password=welcome";
string Query = "SELECT * FROM 'userinfo'.'users' where 'username' = @userid and 'password' = @password)";
MySqlConnection conDatabase = new MySqlConnection(constring);
MySqlCommand cmd = new MySqlCommand(Query, conDatabase);
cmd.Parameters.AddWithValue("@userid", this.userid_txt.Text);
cmd.Parameters.AddWithValue("@passone", this.passone_txt.Text);

[code]....

Fixed the crash error, simple typo but now I am getting SQL Syntax errors which I originally believed I fixed.

View 1 Replies View Related

C++ :: Input Validation - Program Cannot Accept Negative Numbers

Nov 12, 2014

#include <iostream>
#include <iomanip>
using namespace std;

// Function Prototype
void sortArray(int array[], int size);

[Code] ....

This program was made to allow students to enter as many test scores as they want and the program will show them in ascending order and then will calculate the average of all test scores. It works wonderful until you enter a negative test score and then it throws the averaging process off. I can't seem to be able to make the program not accept the negative numbers.

View 1 Replies View Related

Visual C++ :: Program Must Accept 7 Values Or Stop It When Type S

Oct 27, 2014

I want to fix this code. The program must accept 7 values or stop it when you type s. The code not only couts the element, but also some other random numbers.

Code:
#include<iostream>
using namespace std;
int main() {
int numb[7];
int i;
char s;
for (i=0;i<=6;i++)

[Code] .....

View 2 Replies View Related

C++ :: CString Program - Function Should Accept String Object Arguments

Feb 23, 2015

Write a function named replaceSubstring. The function should accept three C-string or string object arguments.

Let's call them string1, string2, and string3. It should search string1 for all occurrences of string2. When it finds an occurrence of string2, it should replace it with string3.

For example, suppose the three arguments have the following values:

string1: "the dog jumped over the fence"
string2: "the"
string3: "that"

With these three arguments, the function would return a string object with the value "that dog jumped over that fence." Demonstrate the function in a complete program.

View 1 Replies View Related

C++ :: Program Compiles But Doesn't Run

Apr 28, 2013

My program compiles but doesn't run, Here is the screen shot of debugging

//DynBag.cpp : Implementation File
#include <stdexcept>
#include <iostream>
#include "DynBag.h"

[Code] .....

View 3 Replies View Related

C :: Program To Accept Only Numerical Values And Gives Error If Character Or Symbol Entered

Nov 11, 2013

How can i make my program to accept only numerical values and gives a error notice if a character or a symbol is entered???

View 4 Replies View Related

C++ :: Program Doesn't Alphabetize Strings

Jan 18, 2015

I can't seem to get my program to alphabetize a vector string. It displays the names, but not in a sorted order.

void sort_names(vector<string> &nameList) {
int i, minIndex;
string minValue;
int size;
size = nameList.size();

[Code] ....

View 4 Replies View Related

C++ :: Program Doesn't Read The End Of File Sequence

Aug 16, 2014

i have a question, i'm studyng the string library type and i have to write this program :

Code:

std::string word;
while (std::cin >> word) {
std::cout << word << std::endl;
}
why if my input is :

hi my name is ^Z

the output is :

hi
my
name
is

why the program doesn't fall out from the while loop ?

why my program does not recognize my sequence of end of file ?

View 5 Replies View Related

C :: Program Doesn't Print Data From Socket

May 7, 2014

I created a basic socket server, which listensing for incoming udp data. When I run the netcat program, I get a response:

Code:
$ nc -luv 1732
Connection from 10.50.11.12 port 1732 [udp/*] accepted
(?@??8?? ??.?n?5
(?@??8?? ??.?n?5|?>)
(?@??8?? ??.?n?5|?>)
^C |?>)

But with my c program it doesn't give the response. It should say something like "here is the message: " and then give a message.

Code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>

[Code] .....

View 2 Replies View Related

C :: Program Doesn't Properly Compute Simple Polynomial

Feb 7, 2014

The program will ask for the user to enter a value for x, then compute the following polynomial: 3x^5 + 2x^4 - 5x^3 - x^2 + 7x - 6.However, when I double check it with my calculator I get a wrong answer for random values of x. To simplify my problem I'm using only integers.

Code:

#include <stdio.h>
int main(void)
{
int x, polynomial;
}

[code]...

View 5 Replies View Related

C++ :: Program Output That Doesn't Wait For Replies But Still Captures Them

Jul 21, 2013

I am trying to write a program that can communicate over a very latent internet connection involving a cellular modem. I have some software packages that handle all the telnet like business and will pipe stdout and stdin to a program I can have it execute.

The problem I am running into is that I have to send about 900 ASCII commands to an instrument to request data but it takes about a second between when a command goes out and when a reply comes back. This will wind up taking a very long time and I am looking to speed it up. All of the commands are independent of the reply so what I need to do is create a program that can send all 900 commands with maybe 10ms break between them and to not wait for a reply. It then needs to read the replies and write them straight to a file.

It seems like this should be achievable in C++ but I only have a very basic understanding of the language and thus am not sure where to start.

I am open to using other languages but thought C++ would be a reasonably good start so I can distribute the program to my coworkers. All of our work machines are Windows but if there is a simpler solution from Linux, I should be able to work something out. I'm just trying to avoid complication.

View 5 Replies View Related







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