C++ :: Program That Prints Out Random Numbers
Nov 1, 2013
output should look like this -
So far i have this
[code]#include <iostream>
#include <time.h>
using namespace std;
int main() {
srand(time(NULL));
[Code] .....
I am getting these errors when i compile it
random.cpp: In function âint main()â:
random.cpp:23: error: expected â,â or â;â before numeric constant
random.cpp:24: error: âRâ was not declared in this scope
random.cpp:25: error: âRâ was not declared in this scope
random.cpp:26: error: âRâ was not declared in this scope
random.cpp:27: error: âRâ was not declared in this scope
random.cpp:28: error: âRâ was not declared in this scope
View 3 Replies
ADVERTISEMENT
Jan 27, 2015
I have a program that makes change from an amount. It works fine, but the output is the correct output looped over and over. I have tried everything, but it still doesn't work. For example, a amount of 98 should print
3 quarters
2 dimes
0 nickles
3 pennies
but instead it prints
3 quarters
2 dimes
0 nickels
3 pennies
0 quarters
2 dimes
0 nickels
3 pennies
0 quarters
2 dimes
0 nickels
3 pennies
Why it's doing this?
Code:
#include <iostream>
using namespace std;
int coinscount(int& amount, int value) {
int tracker = 0;
int amountdimes = amount;
[Code].....
View 3 Replies
View Related
Oct 29, 2013
I need to make a program that prints out 10 random questions from the 15 questions in a .txt file, and then print out the choice IN RANDOM.
View 7 Replies
View Related
Feb 9, 2015
I have a program where the user inputs a line of integers, and then all unique ones are outputted. It works fine-almost. It prints the numbers correctly, but prints them more than once and I'm not sure why.
Code: #include <iostream>
using namespace std;
int main ( ) {
[Code]......
View 10 Replies
View Related
Mar 3, 2014
When I go to run the Fibonacci function ( fib ), it begins to return incorrect calculations towards the higher numbers, but then seems to correct itself for a little bit, but then does it again and ultimately crashes. And the program seems to be crashing at random numbers. Sometimes the it will make it up to F(55), other times it will only get to F(20).
Also, when I go to run the program on a Linux server, it segfaults, but it doesn't when I just run it on my IDE. the function adds two arrays with individual digits together. It does this to allow the program to add numbers that would exceed the boundaries of INT_MAX.
Here is the header file "Fibonacci.h":
Code:
#ifndef __FIBONACCI_H
#define __FIBONACCI_H
typedef struct HugeInteger
{
// a dynamically allocated array to hold the digits of a huge integer
int *digits;
// the number of digits in the huge integer (approx. equal to array length)
int length;
} HugeInteger;
}
[code]....
View 12 Replies
View Related
May 6, 2013
#include <ctime>
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
[Code] ....
Write a program that keeps generating two random numbers between 1 and 10 and asks the user for the product of the two numbers, e.g.: "What is 4 x 6?". If the user answers correctly, the program responds with "Right!"; otherwise, it displays: Wrong! 4 x 6 = 24.
Generate as many pairs of numbers as specified and get the answers from the user for each. If at any time, both numbers are the same as last time, generate two new numbers before asking for the answer. Continue generating 2 new numbers until at least one is different from last time.
After presenting the number of pairs of numbers specified and getting the answers, display how many the user got right; e.g.: You got 4 of 5 right. Then, ask if he or she wants to play again, like so: "Do you want to play again? [y/n]". If the user answers with 'y' or 'Y', it again reads the number of questions to ask and generates that many pairs of numbers and reads the answers like before. If the answer is n or N, it quits generating numbers. If the answer is anything but y, Y, n or N, it tells the user to enter one of those letters until it is.
When the user decides to quit and has got less than 75% of all the questions right, the program displays the multiplication table (1x1 through 10x10) before terminating.
After displaying the table, randomly generate two numbers between 1 and 10, display their product and first number and ask the user to guess the second as more practice. For example, the program will generate 7 and 9 and will display 63 and 7 and the user must guess the second number (i.e.: 9). Do this 3 times. Do not repeat code. Use a loop to do this 3 times.
Use a nested for loop to display the table; a bunch of cout statements will not be acceptable. You must also use a loop for any part that calls for repetition such as generating 5 pairs of numbers.
The following is a sample interaction between the user and the program:
Enter the number of questions to ask: 5
1. What is 3 x 9? 27
Right!
2. What is 2 x 7? 14
Right!
3. What is 8 x 9? 63
Wrong! 8 x 9 = 72
4. What is 6 x 3? 21
Wrong! 6 x 3 = 18
5. What is 2 x 9? 18
Right!
You got 3 out of 5 right which is 60%.
Play agian? [y/n] n
View 10 Replies
View Related
Feb 10, 2014
The program must print out 5 random numbers, from 1 to 45 and 100 different sequence.. Now I want each number of sequence to be different and not the same....
for example
1,2,3,4,5
6,7,8,9,10
....
...
..
here is my code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main () {
int xRan1;
[Code] ....
View 2 Replies
View Related
Apr 16, 2013
i have a programming problem and i am unsure of what the final part is.the question is:
Write a program that fills an array with 10 random numbers between 1 and 20, displays the 10 numbers, and finds the sum of the 10 numbers. Call the getData, displayData, and getSum functions from the main function. Output the sum from the main program by calling the getSum function within a printf statement.
i am just really unsure of what this is--getData, displayData, and getSum functions from the main function. Output the sum from the main program by calling the getSum function within a printf statement.what i have got so far is;
Code:
#include <stdio.h>
#include <stdlib.h>
#define ARY_SIZE 10
int main() {
int randomNumbers[ARY_SIZE], sum = 0, i;
[Code]....
View 1 Replies
View Related
Mar 1, 2014
I having some issues with two different programs here... One of them crashes and returns random negative numbers whenever it reaches a "fscanf" function and the other displays a "Polink fatal error: access denied" error.
Code:
/* Evan Wentz */
/* Pike - ET2560 */
#include <stdio.h>
#define MAX_ACCTS 100
int accounts [];
double balances [];
[Code] ....
I thought the reason this kept crashing before was because I didn't type the data into the text file it was writing too correctly, but I made another program to do that, and it crashed whenever it got to fprintf. Program works perfect besides the file stuff...
View 6 Replies
View Related
Aug 31, 2013
I want to make 10 random numbers thus making 10 random flips of a coin. I am getting 10 tails or 10 heads!
Code: #include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[])
{
[Code].....
View 4 Replies
View Related
Sep 17, 2013
Write a program asks the user for a positive integer value and then prints out all perfect numbers from 1 to that positive integer. I have been trying for some time, i found a way to check if its a perfect number or not but could not find a way to prints out all perfect numbers from 1 to that positive integer. I am here so far.
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int n,i=1,sum=0;
cout<<"Enter a number: ";
[Code] ....
View 4 Replies
View Related
Apr 21, 2014
You should implement the following function:
int is_phone_number(char* string)
This function will take in a string and return 1 if it looks like a phone number 0 otherwise. A phone number takes the form (xxx)-xxx-xxxx where the xs are digits 0-9. So for example (123)-456-7890 is a valid phone number while 123 456-7890 is not.
You should also write a main function that parses a text document and prints out all of the phone numbers found. Hint, look up the strtok function.
Sample input:
Please call me at (123)-456-789 sometime tonight.
Sample output:
Phone number : (123)-456-7890
View 5 Replies
View Related
Oct 8, 2014
I need to make a program that prints certain pictures. My program compiles successfully. However, I cannot figure out how to view the ppm output. When i run the program i get a lot of random text.
View 2 Replies
View Related
Jan 1, 2015
I'm making a program that prints a triangle of @ signs given rows (but not columns).
For example, the output with rows = 4 would be:
@@@@
@@@
@@
@
and rows = 3 would be:
@@@
@@
@
However, trying to make this has given me a program that does something similar (but not the same):
for example, with my current program rows = 4 outputs:
@@@@
@@@
@@
@
and rows = 3 gives
@@@
@@
@
It seems that it's just missing a space (and therefore a setw and setfill), but I found 2 problems:
1. The space needs to not apply to the first line.
2. I can't get it to make a space before each row without making a space between each column.
My current code is:
#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {
int rows;
[Code] ....
I have tried putting in << setws and << setfills of various values but it seems to always apply to between each column as well as at the start of each row- what do I do?
View 4 Replies
View Related
Jan 20, 2015
I have a program that prints out pascal's triangle. One problem: it isn't a triangle. The output doesn't work. This is what it should print:
Code: How many rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 and this is what it does print: Code: Enter a number of rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
[Code]....
View 3 Replies
View Related
Sep 29, 2014
So I need to make a program that reads distance and number of days of a person that is buying a ticket. If distance is greater than 1,000 kilometers AND the person stays more than 7 days, the discount is 30% of the ticket. The cost per kilometer is $1300. Print the ticket with discount.
I used variable distance as float because it will be multiplied with 0.3 for the discount... not sure if I'm right on that.
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
float distance;
int days;
[Code] .....
I tried another way but haven't done it in code...
ask for distance
ask for days
Ticket= (Dist x 2 x $1300)
If (dist>1000) && (days>7)
cout<<Ticket=Ticket * 0.3;
else { cout<<Ticket;
View 2 Replies
View Related
Nov 4, 2013
#include <iostream>
using namespace std;
int main()
{
int num = 2;
int count = 0;
while (num <= 100)
[Code]...
The code works fine but I need the results to print out like
2 4 6 8 10 12 14 16 18 20
22 24 26 28 30 32 34 36 38 40
instead of
2
4
6
8
10
12
I don't know how to do this.
View 7 Replies
View Related
Jan 12, 2015
So I need to make a program that prints a triangle of symbols in a certain direction.
For example: Code: How many rows? 3
@
@@@
@@@@@
How to do that. It's rare that I post without figuring anything out, but I'm just simply not sure. I have a program that prints a triangle in a similar direction, so maybe if I could get some hints as to what to do with that (HINTS, not direct source code) .
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {
[Code] .....
View 6 Replies
View Related
Jan 6, 2015
I am working on an assignment to enter a number and print all the prime factors of that number. I have that working, but the assignment demands the output be formatted in a strange way which I can't figure out. For example, in my current program entering 10 gets me 25, which is actually 2 and 5. But it should get me: ( 2 * 5 ) but I can't figure out how to do this. On the chance you need it, my code is below:
Code:
#include <iostream>
using namespace std;
int main( )
{
cout << "Number: ";
[Code].....
View 12 Replies
View Related
Mar 9, 2013
Write a program that prints a multiplication table using nested loops. In main ask the user for the smallest column number , the largest column number and the size of the increment. Ask the user for the same information for the row values.
In the example the column values entered are: 5, 15 and 2 and the row values 3, 6 and 1.
Given those numbers you would generate the following table.
Multiplication Table
| 5 7 9 11 13 15 ___|___________________________________ | 3 |
15 21 27 33 39 45 4 | 20 28 36 44 52 60 5 | 25 35 45 55 65 75 6 | 30 42 54 66 78 90
Print the 24 values with the grey background. The other numbers show the values to be multiplied.
Code:
#include<stdio.h>
main() {
int a,b,c,d,e,f;
int i,j,total;
printf("Please enter smallest column number: ");
scanf("%i",&a);
printf("
[Code] ....
Challenge:
As an added challenge try to print out the column
headings (5 7 9 11 13 15) and the row headings (3 4 5 6)
View 1 Replies
View Related
Oct 8, 2013
I'm trying to create a program that prints a number of dots specified by the user, there 4 options to do any loop type or to exit the menu. i'm having problems making it so that after you enter a value and it displays the specified number of dots it clears the results. Also we have to make it so that if a negative integer is entered it still prints out the appropriate amount of dots ie: user puts -9 it prints 9 dots, i know you use the abs() function but it doesn't seem to be working for me. I'm assuming my problem with the abs function is i'm not using it correctly. Use case 1 as the example for the rest because I'm trying to implement everything on one case at a time
Code:
int main() {
//initialization statements
int Num1 = 0;
char dot = '.';
[code]....
View 7 Replies
View Related
Jun 21, 2013
the question is; Write a program that prints out the memory addresses of each element in a two-dimensional array. Check to see if the values printed out make sense to you based on the way I explained it before.
Below is the code I have done. I am having problems printing the "-" sign to keep formatting with the board when the user enter in different dimensions other than [4][4].
Code:
#include <iostream>
using namespace std;
void printTable (int x, int y) {
int **p_p_twoDimension = new int* [y];
for (int i = 0; i < y; i++) {
p_p_twoDimension[i] = new int [x];}
[Code]...
View 12 Replies
View Related
Apr 10, 2014
How do I write a program that'll interpret "M" and "F" inputs and print a "you're a guy" or "you're a gurl" message?
Code:
#include <stdio.h>
#include <conio.h>
char gender;
char main(void) {
printf("type M or F
[Code] ....
View 5 Replies
View Related
Jan 18, 2015
I'm just getting back into the swing of things after a long time of not programming. I'm trying to create a program which takes in command line arguments and prints the last one. My code is as follows:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
string x;
vector<string> arguments;
[Code]...
And the error message I receive, a simple but frustrating one, is as follows:
Enter arguments, enter STOP to stop: Segmentation fault...
View 1 Replies
View Related
Apr 12, 2015
I need to create a program that prints a certain number of asterisks based on user input. The user inputs 5 and I want my program to output "*****". How would I do this in C? I've tried printf("%#**", myvariable) but this does not work it only prints "*".
View 1 Replies
View Related
Oct 17, 2014
I'm trying to make a C++ program that generate 6 random numbers ( from 100,000 to 999,999 ), okay, so I wrote a few lines..
Code:
srand(time(0));
for (int i = 0; i < 5; i++)
{
std::cout << 100000 + (rand() % 999999) << std::endl;
}
The problem is, that it generates numbers like this:
117,207
123,303
131,083
... etc etc..
They're all starts with 100K, i want them to be an actual random..
View 8 Replies
View Related