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] ....
#include<iostream>
using namespace std;
int main() {
int a[9],x,f=1;
cout<<"Please enter an integer [0-10 only] : ";
[Code] ....
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.
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
#include <iostream>
#include <iomanip>
#include <fstream>
[Code]....
i have already tried putting system pause or cin.get after it, but no luck
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]....
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
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 RelatedI'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] .....
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].....
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
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
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] ....
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].....
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
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 RelatedI 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.
#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.
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] .....
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.
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] .....
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 RelatedI 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] ....
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 ?
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] .....
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]...
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.