C++ :: Program To Determine Number Of Inputted Riders And Closes When Input Is -1?

Jan 16, 2015

I seem to be having a logical error but can not find the sources.

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

[Code] ....

View 1 Replies


ADVERTISEMENT

C++ :: Read User Input To Determine Different Discounts By Number Of Units Sold - Errors In Program

Jun 23, 2014

it will not run and im not sure why. I have a couple of errors, but I'm not sure why.

Here is my code.

//Reads input from user to determine different discounts by number of units sold

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

int main() {
//Declaration and Initialization of variables
int quantity;
double discount,price = 99.00,totalCost;

[Code] ....

View 1 Replies View Related

C/C++ :: Program Closes When Using Any Number In Switch

Feb 17, 2015

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

[Code]....

when running the program it closses after the switch.

View 2 Replies View Related

C :: Program That Determine Day Number In A Year For A Date?

Oct 21, 2013

Write a program that determines the day number (1 to 366) in a year for a date that is provided as input data. As an example, January 1st, 1994, is day 1. December 31, 1993, is day 365. December 31, 1996 is day 366, since 1996 is a leap year. A year is a leap year if it is divisible by four, except that any year divisible by 100 is a leap year only if it is divisible by 40. Your program should accept the month, day, and year as integers. Include a function leap that returns 1 if called with a leap year, 0 otherwise. Extend the requested solution so that your program continues to prompt the user for new dates until a negative year is entered. This is what I have so far.

Code:
#include <stdio.h>
#include <stdbool.h>
int main(void) {

int d,m,y;
int days=0;
int k;

[Code] .....

I am unsure how to make this a loop so that it keeps asking for dates?

View 9 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/C++ :: Infinite For Loop - Program Just Closes

Feb 10, 2015

So I learned how to make a basic for loop and I decided to try my best to make an infinite one. Every time I run it, it doesn't say anything and just closes. Visual Studio doesn't say there's anything wrong with my code.

Here's the code

#include <iostream>
#include <conio.h>
using namespace std;
int main () {
int d = 9;
for(int k = 10; k < d; k = k +1) {
cout << "For loop value = " << k << endl;
getch();
} }

View 4 Replies View Related

C++ :: Program Compiles / Runs But Closes Right Away When Finished

Oct 15, 2013

Program compiles and runs no problem but closes right away when finished.

Heres the code:
Code: #include <iostream>
#include <cmath>
using namespace std;
double calcDistance(double,double, double, double);
float calcKilometers(float, const float) ;

[Code] ....

View 3 Replies View Related

C++ :: Add Each Number From Zip Code Inputted By User

Oct 27, 2013

I came up with this code to try to add each number from a zip code inputted by the user but I think I'm adding up the ascii values not the real values the user is inputting. How I can go from ascii to the real digit. This is my code so far

#include <iostream>
#include <iomanip>
#include <string>
#include <conio.h>
using namespace std;
int main() {
int total = 0;
char ch[5];

cout << "Please input your 5 digit zip code: ";

[Code] ....

View 4 Replies View Related

C++ :: Reciprocal Of User Inputted Number

Jan 4, 2013

I've been working on this program and I have it all pretty much down, but I just need one thing that I can't, for the life of me, think of! I need to find the reciprocal of a number that the user inputted (ex: if user input was 2 output would be 0.5 or if input was .6, out put would be 1.6 repeating). If theres a simple way, I can't think of it.

View 2 Replies View Related

C :: Print All Numbers Up To The Inputted Number Vertically

Feb 19, 2013

I've written a program which takes a character string and then prints each character vertically so that for instance the string 123 can be written as
1
2
3

no what i need is for all the numbers from zero to the inputted number to print the numbers digits vertically but each number to be printed horizontally so that for instance an input of 11 prints

1 2 3 4 5 6 7 8 9 1 1
0 1

i've made it so that i can print all numbers up to the inputted number vertically; however, i am stuck with a method for making each number print horizontally as described above.

View 3 Replies View Related

C :: How To Repeat A Loop Based On Number Inputted By User

Oct 21, 2014

How can i repeat a loop based on the number inputted by the user?

View 4 Replies View Related

C++ :: Counting Number Of Lines Inputted By User (File Stream)

Feb 12, 2014

So I'm trying to count the number of lines in a text file that is inputted by the user. Also the code doesn't sum up the last number of the text file (exmp it calculates and print only 14 from 15 numbers). I'm a beginner in c++ programing.

View 3 Replies View Related

C++ :: Count Number Of Vowels Inputted By User - Isvowel Function

Mar 30, 2013

I am trying to create a code that simply counts the number of vowels inputted by the user. Here's where I am.

Code:
#include <iostream>
using namespace std;
bool isVowel(char ch);
int main() {
int count=0;
char character;
int vowelcount=0;

[Code] .....

View 14 Replies View Related

C/C++ :: Determine Input Type Without Converting

Sep 19, 2014

Originally I had to create a simple integer palindrome program that looped while the user entered 5 digit inputs (entering -1 stopped the loop). I did this using a conversion to string, reading the length to determine if the length was valid, and then reading the string forward and backwards inside of a while loop. (snippet below)

while( digitsEntered != -1)//Allow user to quit by entering -1 to end the loop
{
ostringstream convert;//conversion stream
convert << digitsEntered;//converted text from number goes in the stream
convertedString = convert.str();//store the resulting conversion to convertedString

[Code] ....

The next stage of this program was to do the same thing with strings instead of integers. However, the option to end the loop by entering -1 is still a requirement.

I think the way to do this is to first determining whether the input is a string or an integer, and if it is a string then read it and if it's an integer determine if it's -1. However, whenever I write code to do this, it converts strings to 0 so the string is not stored and cannot be read to determine if it is a palindrome. Is there a way to determine the type of input without converting it into a different type i.e. read string and then keep string or read number and keep number?

View 3 Replies View Related

C :: Determine Minimum Number Of Changes That Can Be Made

Mar 7, 2013

You are given an integer, perhaps a very long long integer, composed of only the digits 1 and/or 2. You have the ability to change a 1 digit into a 2 and a 2 digit into a 1 and must determine the min. number of changes that you can make resulting in no 2 digits remaining in the number that are in a position(in terms of powers of ten) higher than any 1 digit.

example:

2222212 number of changes:1
1111121 1
2211221 3
1122112 2

no negative numbers.

how to get started. Also I'm not allowed to use anything related to arrays or sorting.

View 6 Replies View Related

C/C++ :: Determine Smallest Number Xmin

Jan 21, 2014

In a fashion similar to that in Fig. 3.11(shown below), write a short program to determine the smallest number, xmin, used on the computer you will be employing along with this book. Note that your computer will be unable to reliably distinguish between zero and a quantity that is smaller than this number.

fig311.png

View 2 Replies View Related

C :: Read String From Input Then Determine Which Character Is The Largest

Jan 12, 2015

I'm very new to c programming and I have some background in C# and java. I am supposed to read a string from input then determine in that string, which character is the largest, i.e. I think b>e and e>z, e.t.c. If the string is empty I should return ''.

I haven't done any programming in C before and I don't know how to handle strings and characters in C.

View 2 Replies View Related

C++ :: Take User Input Selection Of Columns And Determine Array

Aug 29, 2013

I am writing code for a program that will take user input selection of columns and determine an array based on that.The number of columns will be user selected.The number of rows equals 3^(columns) <--exponent not XOR

- This is because each column has the possibility of having the numbers 0,1,or 2

For example, if the user were to select "4" columns, then the array would have 4 columns and 3^4=81 rows. Then I would like to populate this with all of the possible combinations of 0,1,2

i.e.
0000
0001
0002
0010
0011
0012
0020
0021
0022
0100
....
2220
2221
2222

how I would create the "For" Loop for this?

View 19 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 :: Determine Number Of Binary Palindromes In Given Range?

Oct 26, 2013

Write a program to determine the number of binary palindromes in a given range [a;b]. A binary palindrome is a number whose binary representation is reading the same in either forward or reverse direction (leading zeros not accounted for). Example: the decimal number 5 (binary 101) is palindromic.

View 2 Replies View Related

C :: Make Program That Takes Number Input From Tuser?

Jul 27, 2013

I have to make a program that takes a number input from the user and prints the corresponding fibonacci sequence number. For example, for the input of 3, it should print 2 since the third term in the fibonacci sequence is 2.

I am not sure how to do this so for my attempt, I used the formula found in this website. A Formula for the nth Fibonacci number

Here is the program so far. It doesn't produce the correct output.

Code:

#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#include "math.h"

[Code]....

View 11 Replies View Related

C++ :: Program To Make A Table For Any Input Number - Do While Loop

Nov 27, 2014

Write a program to make a table for any input number and then continuesly ask to press y to print more table and if you press any key other than y then program must be terminate using while loop and do while loop. How to start or end with it.

View 2 Replies View Related

C++ :: Writing Program That Asks User To Input Number?

Sep 11, 2013

im writing a program that asks the user to input a number 1-10 and will transform it into the roman numeral of that number but it seems that its not after the user inouts the number nothing will output

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

[Code]....

View 3 Replies View Related

C/C++ :: Program To Allow User Input And Output Perfect Number

Mar 11, 2014

The problem that I am having is that , the program outputs numbers that are perfect numbers and im not sure where i can add a statement to make it so that if it isn't a perfect number it doesn't output...

#include<iostream>// allows user input/output
#include<conio.h>
#include<fstream>//data file / result file
#include<iomanip>
#include<cmath> // math function
#define in_file "data.txt"
#define out_file "result.txt"

[Code] ....

View 3 Replies View Related

C++ :: Create Program That Has User Input 5 Digit Number?

Mar 9, 2013

Im trying to create a program that has the user input a 5 digit number. If it's between 10000 & 99999, it will do one thing..(just saying 'yes' for now. Outside those numbers will prompt the user to input again. However, if the user inputs the exact digits 76087, it should display 'term'.

This current code is displaying 'term' whenever the user inputs the 5 digits.

Code:

#include <iostream>
using namespace std;
int main() {
int pin;
cout << "Welcome to Movie Food
Enter your 5-digit pin code: " ;

[code]....

View 14 Replies View Related

C++ :: Write Program Which Tells User If Number They Input Is Prime Or Not?

May 2, 2014

So I need to write a program which tells the user if the number they input is prime or not. I have done so and included the code below. My problem is that I need to allow the user to input if they want to enter another number after the first one using y or n and I am having trouble figure it out.

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

[Code].....

View 5 Replies View Related







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