#include <stdio.h>
int main(int argc, char* argv[])
{
int i=0;
int count=0;
while(i<5)
i++;
count++;
printf("The value of count is: %d
", count);
return 0;
}
It only prints: The value of count is 1. I'm confused on why it doesnt print the value of the count is 5
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
you have to use the brackets to enclose just like I used in my code right here.It is a simple while loop that is a countdown.
#include <iostream> using namespace std; int main() { int n =10; while(n>0){ cout << n << ", ";
[code].....
when I take the brackets away from my while loop, my code will still execute but it just prints out the number "10" repeatedly. I was just wondering why it does this and why the compiler does not throw out an error when I leave off the brackets after the "while()".
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 ( ) {
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)
Im trying to make a Tic Tac Toe board for an assignment. Right now it compiles fine but when I enter an x or o it does not update the board it just prints out the '.'s that the board is initialized to. Also, when I get to player 2 the board will printout twice so its 6 rows or 3 columns. The project uses a main to ask who starts then goes to a play function that asks for inputs and calls the makeMove function to place the x's and o's and the print function to display the updated board.
bool Board::makeMove(int rowIn, int columnIn, char currentPlayer) { if (playBoard[rowIn][columnIn] == '.') { playBoard[rowIn][columnIn] = currentPlayer; return true;
The print statement below I commented prints out unusual characters. I have two strings from the command line that I pass to the TKCreate function. Inside the function the strings print out fine, but when I return a pointer to the struct back to the main method one of the strings prints out fine, but the other one prints out unusual inconsistent characters.
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 ( ) {
#include <stdio.h> int main () { int num; char choice; printf(" Welcome to a Menu-Demo Program Please select one of the following actions R - Programmers Rock! F - Programming is Fun! G - Geeks Rule! X - Exit program Selection ==>__ "); do{ choice = getchar(); switch(choice)
[code]......
I am currently writing a simple program that utilizes switch statements. When I run my program, it always displays the message for the default case.
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: ";
Well still working on my project, now the bubble sorting failed. For some reason the first slot in the array is empty and when I attempt to enter a record to access, it just crashes or prints a blank record. Here is my code for the viewing of the record and a SS of the empty array slot.
Code: void searchRec(void) { void Printing(int *ver, int *max); FILE *fPtr; struct Students vStudnt; int set; int ver; int i = 0; int fin = 0; int sel; char order;
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 = '.';
I'm trying to find out, how to do printf so that it prints out text in the center of the window. I know how left and right justifyment is... but how to get to the center? C...
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: ";
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];}