-Create three files namely all_numbers, odd_number and even_number. -Get the number of records and the numbers to store from the user. -Save all the numbers in "all_numbers" file. -Read each number and check whether it is odd or even. -Store the odd numbers in odd_number file and even numbers in even_number file. -Finally, print the numbers stored in odd_number and even_number files.
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
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 ( ) {
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.
Using PIONTER NOTATION ONLY, write a function that receives two arrays of integers like A and B above. The function should swap the values in A and B. You may NOT use array notation [ ]. Also, you have to use pointers to move among array cells. Note: Both arrays are of the same size, and size should be variable in the function.
write a function accepts two arguments, an array of integers and a number indicating the number of elements in the array. the function should recursively calculate the sum of all the numbers in the array. Demonatrate the use of the functions in a program that asks the users to enter an array of numbers and prints it sum
i had done this but it wont work
#include <iostream> #include <conio.h> #include <iomanip> using namespace std;
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.
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?
[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
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)
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 ( ) {
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: ";
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)
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 = '.';
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];}
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...
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 "*".
I would like to understand a function on strings. Below is a code that I took from my teacher where the user inputs a string and prints out the length of the string.
Code: #include <stdio.h> #include <string.h> int main() { char str[100]; int i = 0;
[Code] ....
Now I understand that it returns the count in "int" so my question is:
Let's say i declared
Code: int count = 0; at the beginning of the code and then made Code: count = strlen(str); why wouldn't i have the same result? Is there a way to do it also?
I compiled a simple program using a function to add two integers, in order to understand the difference of calling by value vs by reference.
Code:
#include <stdio.h> int add(int a, int b, int sum); int main() { int a, b, sum; printf("Please enter two integers "); scanf("%d%d", &a, &b);
[Code]...
I used these two (one, two) pages I found in the net while studying the subject. So here are my questions...
(a) Do I understand correctly that in the above code all a, b and sum are passed by value? (b) If I wanted only sum to be passed by reference, how the above code would change? (c) If I wanted all (a, b, sum) to be passed by reference, how the above code would change?
I created a program in C that opens a text file and read integers.
File `numbers.txt`: > 5 6 4 6 3 4 1
I use some restrictions with the `fscanf()` library and read the file, just for the record, and if everything goes fine I proceed to the next part of code (I know I could use `fget()`, but this is how I done it).The next part of the code will be this:
- First, I want the program to read the numbers from right to left. I look for an answer in google and many C courses, but I couldn't find a working solution. I think that the code is pretty simple, though I can't find it. **To be clear for the next part, we read the numbers from right to left.**
- Then, this is the hard part for me: I want the program to read the numbers and if the next number is higher (**not equal**) than the last one to keep it in memory, **only if it's higher than the last.** This can be continue for **1 through 500.000 numbers.**
- Then when the procedure done, I want to print how many numbers are greater than the last one and save it to a file, which I can do it if I solve the last problem.
We have the below numbers: 5 6 4 6 3 4 1
The program starts to read the numbers from right to left.Now which and how many numbers are greater than the last one?
The answer is 3 numbers: 5 6 4 [6] 3 [4] [1]
Then the program will print the number 3 with a message and save it to a file called `xxx.txt`. I am posting the `main` code, not all the code just what you need to solve the problem:
Code:
#include <errno.h> // macros for reporting and retrieving error conditions #include <stdio.h> // load main C library function #include <stdlib.h> // need that for many reasons ;) #include <string.h> // loads various of characters functions }
[code]....
In conclusion, I want 2 pieces of code:
- One to read the numbers from right to left - One to make the above procedure
Add a program that declares two arrays of 5 integers each. Provide one function to load one array with random numbers from 1 to 25, another to fill the other array with user supplied values, and a third function to print an array. The main function should declare the arrays and use the functions to fill each array and print them both.
The code i have so far is #include <cstdlib> #include <iostream> using namespace std; void printaaray(int printarray1[], int printarray2);