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.
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];
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.
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
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:
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
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.
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:
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*/
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)
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
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:
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:
I am trying to find the max number entered by the user, and it should terminate when a negative number is entered. For my code, it will just end when the user inputs a lower number than the previous. i.e.- 10 20 15 "The highest number is 20" when it should be "10 20 5 40 15 -1" "The highest number is 40". No arrays or do/while loops either.
#include <iostream> using namespace std; int Max(int x); int main() { int x;
There's this program I'm trying to code where the user gives input of 2 values.
Sample :-
Value of X: 1234 Value of Y: 234567 Reversed value X: 4321 Reversed value of Y: 765432 New value as Z: 1223344567 (each number was taken in both X and Y)
Now the thing is I could do the reverse, and I've been trying to find out how.
Here's my code,
#include <iostream> using namespace std; int main(){ int x=0, y=0; int reverse_x=0; int reverse_y=0; int z = 0; int l;
[Code]....
What I thought about that area where I've put a comment on, I was wondering if I code a loop for the amount of times x gets divided by 10 until it becomes 0 and store it in the value, same thing for Y, and add the value together to get Z. But if that's how it is then how I could use that concept here.
There's this program I'm trying to code where the user gives input of 2 values.
Sample :- Value of X: 1234 Value of Y: 234567 Reversed value X: 4321 Reversed value of Y: 765432 New value as Z: 1223344567 (each number was taken in both X and Y) Now the thing is I could do the reverse, and I've been trying to find out how.
Here's my code,
#include <iostream> using namespace std; int main(){ int x=0, y=0; int reverse_x=0; int reverse_y=0; int z = 0; int l;
[Code]...
What I thought about that area where I've put a comment on, I was wondering if I code a loop for the amount of times x gets divided by 10 until it becomes 0 and store it in the value, same thing for Y, and add the value together to get Z. But if that's how it is I can't seem to really get that idea how I could use that concept here. I'm not really good with programming, fairly new at this.
I have been here for almost 3 months looking for answers in my C++ problems.here's some type of code for this.
cout << "Enter value of x: " << endl; //Let's say 5. cin >> x; cout << "Enter equation: "; //Let's say x+1 cin >> equation;
Then the program analyzes that this character "x" has an initial value of 5.I already have the parser for the equation functions (+,-,*,/)This is the only thing lacking. Is there some type of function that i missed?
Program works perfectly fine. I input in the length, width and height. But i want it to display those values for every individual prism when i output... along with the area and volume which i already have. Since i made a vector i won't let me cout it normally.
#include <iostream> #include <vector> using namespace std;