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


ADVERTISEMENT

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 :: 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 :: Write A Code To Find All The Prime Numbers Before A User Entered Number

Apr 9, 2014

I am trying to write code to find all the prime numbers before a user entered number. I started with a working program and when I tried to create a function, it got all messed up.

Code:

#include <stdio.h>
int is_prime( int num );
int get_positive_integer(void);
int main( ) {
int upper; /* upper limit to check */
int num; /* current number to check */
int isprime;
/* used to flag if number is prime or not */

[Code]...

It says the error is on line 23

View 6 Replies View Related

C :: Iterate Through A User Inputted Integer?

Oct 5, 2014

I need to allow the user to input an integer of any length and print out the word of each number in the integer. So the user would enter "324562" and then the output would be "three two four five six two". I'm struggling to understand the best way to do it in C. I know I need a loop that goes through the int but I don't know how to do it

View 7 Replies View Related

C :: User Inputted Validated Grade As Percentage

Jan 2, 2014

I am trying to get this program to accept two inputs Student number and grade and validate them both

However the program skips over the student number

Code attached AssignmentProgram.c

View 1 Replies View Related

C++ :: Add Score Between 0 And 1000 Inputted By User To Total And Increase Level

May 9, 2013

The program is supposed to have a method called Hitscore that adds a score between 0 and 1000 inputted by the user to the total score and increases level by one and print the score to the screen and which level they last completed after each entry . Have the user continue inputting scores to the program until the gamer has finished all 10 levels. After 10 levels, use a method you create called PassScore to have the program compare the score to avgscore (5000). If the score is less than avgscore, have the code respond "You are not angry at all. " if it is above avgscore, then have it respond "You seem quite angry, calm down. " and if it is exactly 5000, have it respond "Average, just average. "

//Angrybird.h
#ifndef ANGRYBIRD_H
#define ANGRYBIRD_H
using namespace std;
class Angrybird {
public:

float newscore;
float level;

[Code] .....

View 1 Replies View Related

C++ :: Creating A Game - Read Prices Of Object Inputted By User From A File

Feb 19, 2013

How do i read a specific part of a file? I am trying to create a game that reads the prices of an object inputted by the user from a file. This is the code i have so far

#include <iostream>
#include <fstream>
using namespace std;
int main () {
ifstream infile;
infile.open ("Objects.txt", ifstream::in);

[Code] ....

The file contains this :

Example objects
( ) store items
(item) (purchase value)/(sell value)

Grocery Store Items
Fish 5 7
Vegetables 10 15
Drinks 20 30

Weapon Store Items
Pistol 300 375
Rifle 400 500
Ammunition 20 30

View 4 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/C++ :: Dynamic Allocation Of Array And Increase Its Size Every Time New Integer Inputted By User

Aug 29, 2014

I'm a little lost with this program. The idea is to dynamically allocate an array and increase its size every time a new integer is inputted by the user. I believe it is a memory leak but as we have just started learning this I'm not sure how to recognise it. Sometimes I can input as many integers as I want other times 2 or 3 before it crashes. When I can input enough values i exit the loop and send it to the sort function and mean calculator function, all works fine there except the last number inputted becomes this huge value not hexadecimal though... As such I'm at a loss as what to look at next, so here you go:

#include <iostream>
using namespace std;
void SelectSort(int [], int);
float MeanCalc(int [], int);
float MedianCalc(int* [], int);

[Code] .....

View 14 Replies View Related

Visual C++ :: Puzzle Game - Implement A Way To Save Board State Throughout User Inputted Path

Mar 16, 2013

I've been trying to figure out how to implement a way to save this board state throughout a user's inputted path. At the end, I need the output to print out the board states (user's path) of how he or she got the puzzle solved. This puzzle is the 15 Puzzle; but we have it to change by the user's input on what size they want to play (3x3 to 5x5). How to save the board state of each user input, then print those out in order from beginning to solved puzzle state. Subsequently, I would also need transferring the board state to change with using a vector to store the size based on user input. How to proceed, using a first search to solve the puzzle from the current board's state.

calculations.h

Code:
/*Calculations set as a header to keep compiling simple and faster*/

#ifndef calculations
#define calculations
int solved[5][5];
void initialize(int board[][5], int);
void slide(int board[][5],int move,int);
bool isBoardSolved(int board[][5],int);

[Code] .....

View 6 Replies View Related

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 View Related

C++ :: Binary Search Function - Return True If Element Inputted By User Found In Array And False If Not

Nov 9, 2014

I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//binary search function
bool search (int array[], int item)

[Code] ....

Why my code does not fulfill it's purpose???

View 7 Replies View Related

C/C++ :: Display Inputted Values Without Overwriting Other Inputted Values

Jun 16, 2014

How can I display my inputted values here without overwriting the other earlier inputted values. It should be displayed like this [URL].... but mine shows this [URL].... I've been stucked here for hours in thinking for an algorithm. Everything is working fine except the PDISPLAY part

#include<iostream>
#include<iostream>
#include<string>
#include<cctype>
#include<cstdlib>
#include <iomanip>
#include <windows.h>
#include<conio.h>

[Code]...

View 1 Replies View Related

C/C++ :: Compare Values Stored In First Array To User Inputted Values In Second Array

Oct 19, 2014

Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.

In order to fix this error: [URL]...

I had to change my array initialization to one with a star in front of it:

char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
to:
char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};

I also changed my 2nd array to one with a star in front of it: char *a2[20];

What does this mean exactly? Putting a star in front of an array?

Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array:

cin>>a2[i];

View 3 Replies View Related

C :: Program That Allow User To Enter A Number N And Print Nth Prime Number

Nov 3, 2013

I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....

EXAMPLE

user enters 55

printf("The 55th prime number is %i", variable");

View 1 Replies View Related

C++ :: Receive Number From User And Output Largest Prime Number

Nov 20, 2014

I am attempting to write code that receives a number from the user and outputs the largest prime number underneath the user's number. There are no errors in my code, but no matter what number is imputed, the program says the largest prime number is 1. I cannot find where the issue is in the code. Here is the code I wrote:

#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num);//function prototype

[Code] ....

View 2 Replies View Related

C :: Code That Takes Two Arrays From The User And Merge / Sort?

Oct 27, 2013

I'm trying to write a code that takes two arrays from the user (presumably in ascending order) and then passes the sizes of both arrays and a pointer to each to a separate "int* mergeArrays" function that will merge sort the two. I've written a lot of the code, but I can't get it to compile. I get errors: lab6.c: In function "main":

lab6.c:31:14: error: expected expression before "int"
mergeArrays(int* firstArray, int size1, int* secondArray, int size2);
^
lab6.c:31:14: error: too few arguments to function "mergeArrays"

[Code] ....

View 2 Replies View Related

C++ :: Give Appropriate Color Code For Resistor After User Input

Sep 18, 2013

I am in the process of writing a program that will give the appropriate color code for a resistor after the user enters an integer value for the resistance needed and selects the tolerance form a list. My question is this: Is there a way to allow the user to enter a value such as 75000 and C++ use each digit separately, as if they entered 7 [enter], 5[enter], 0 [eneter]... and so on? But, then use the entire value as an integer too? Also, it should read a value such as: 45835, as 45000, or 1843 as 1800.

View 1 Replies View Related

C++ :: How To Add A Loop / User-defined Function And Array / Structure To Code

Apr 24, 2012

We had to write a "selling program for computers, laptops and tablets", which I did but for the extra credit, we have to have those three points in the application and I have tried but how to do the "extra credit" part, which I really need.

1.) A loop to prompt the user if they would like to place another order

2.) At least one user-defined function

3.) An enumerated data type, array or struct (structure)

I did one of these three, it's a "DO WHILE" loop asking users if they want to make another order, it's right at the beginning of the code.

Code:

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
double desktop();//function prototype
double laptop();
double tablet();

[Code] ....

View 2 Replies View Related

C++ :: Standard Way To Add Version Number To Code?

Apr 15, 2014

Just wondering if there was a standard way people add a version number to their c++ code? I can just define a variable or #define and write the version number to that, but wanted to know if there is a standard method people use?

View 1 Replies View Related

C++ :: Create Random Number As Zip Code

Nov 21, 2014

I am trying to create a zipcode I write my code like that and it only show "-2" on the screen what happen to my code I can not find mistake!

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
using namespace std;
class Zipcode {

[Code] ....

View 1 Replies View Related

Visual C++ :: Prompt User To Enter Integer Value And Character Code To Indicate Conversion

Sep 14, 2013

I'm expected to write a c program for this question :

Using these header files
#include <stdio.h>
#include <conio.h>

Question : Write a program that will prompt the user to enter an integer value and a character code to indicate whether they want to do a Kilogram to Pounds conversion (A) or a Pounds to Kilogram (B) conversion. Note that 1 kg = 2.2 pounds. The program should then do the necessary conversion indicated by the code and display the newly converted value to the screen.

View 1 Replies View Related

C :: Write A Code To Calculate Minimum Number

May 24, 2014

I'm trying to write a code to calculate the minimum number of coins needed to cover a change. It works fine but i want to display a message telling the user to try again if they type something that's not a number or a negative number. But it's not working. When i type a negative number, the program runs normally and displays a negative value of coins instead of showing the message. And when i type something that's not a number, the program just keeps showing a lot of zeros nonstop. And when i try to compile it with 'unsigned float' instead of just 'float' i get errors.

Code:

#include <stdio.h>
int main()
{
unsigned int coins;
float change;
unsigned int n25, n10, n5, n1;
unsigned int r25, r10, r5;
}

[code]....

View 7 Replies View Related







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