I'm trying to make a program that prints a rectangle using "*" asterisks. I am only allowed to use "for loops" and I simply cannot get this to work properly. Here is my code so far...
Code: int main(void) { //RectangleSize represents the area of the rectangle(width*length) int length, width, RectangleSize;
I have an assignment that calls for a C program using a for loop AND a while loop that will receive an integer (called daNumba) and double it -- Using the integer the program will call the sumFor function and then the sumWhile function. These functions will both sum the values from daNumba to (daNumba * 2) ifdaNumba is positive. If daNumba is not positive it will add the values from (daNumba*2) to daNumba. Both functions will receive the value of daNumba and return a summed value. The only difference between the 2 functions is that sumFor will only use for loops and sumWhile will only use while loops. We are not to use arrays.
The program compiles without error. So far my while loop works for positive integers, but not with a negative integer (I have it commented out) I cannot get the for loop to work properly This is what I have so far -- I am stuck....
Code: #include<stdio.h> #include<stdlib.h> #include<math.h> int main () {
int main ( int argc, char *argv[] ) { int P[150] = {}, i, j; for ( i = 2; i <= 150; i++ ) {
[Code] .....
Using gdb, I noticed that the variable j keep going back to initial value after the interior for loop condition returns false. Why doesn't this for loop terminate right away?
I've just started learning the C language, and I'm stuck on something that is probably quite simple.how to get IF statements working within WHILE loops. My code is below. I am trying to write a program to count the number of words in a sentence, and obviously stop counting after a full stop has been entered. I created a variable called 'spaces' which will increase by one after the user enters a space. However, when the IF statement is in place, the loop never terminates, even if I enter a full stop. When I delete the IF statement, the loop functions correctly.
Code:
#include <stdio.h> int main() { char x; char a; char y; int spaces = 0; }
What output would you expect from this program?" The output was not what I expected. I've psuedo-coded this out and I'm still missing something.
Code:
#include <stdio.h> int main () { int numbers[10] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int i, j; }
[code]....
The output: Code: 1 1 2 4 8 16 32 64 128 256 So when I look at this first loop I see that j = 0, which is less than 10, so then the program statement should commence, which is another for loop. So in this inner for loop I see that i = 0, which is not less than j, so this loop should terminate. Then the value of j increments by 1 and the first go around of the loop has completed.
Now I see that j = 1, so this is less than 10, and the inner for loop commences once again. This time though, i actually is less than j, so numbers[1] = numbers[1] + numbers [0], or numbers[1] = 0 + 1. Now the value of i is incremented by 1 and the first go around of this inner loop has completed. Then the value of j increments by 1 and another go around of that loop has completed.
So now j = 2, i = 1, and numbers[2] ( which is 0 ) = numbers[2] + numbers[1], or numbers[2] = 0 + 1. I was expecting the output to be an array full of 1's. However this is not the case..
I need to make a for loop without: using the math functions like pow, sqrt, etc. or an if-statement.I can only use the basic arithmetic functions like +,-,*, and.The for loop needs to display: 1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192 as the result
How do I make it so my loop works? This is what I have and it doesn't work...and I have no clue how to continue...
k = 0; //k is an int and I have declared it in the beginning of my code for( k = 0; k < 13; k++ ) { printf ( "%d, ",k ); k = k * 2; } printf("%d", x);
I just want to say that I just started learning the language and this is my very first shot at writing a simple program that is not "Hello World" So I recently learnt the basics of the if statement and how to loop in a console application, here's what it looks like:
namespace Testing_IF_Statement { class Program {
[Code].....
And again, this is just what I wrote in a few minutes without putting any thought into it.
Questions: 1)I have heard that the way I'm looping by using the goto statement is considered quite ancient, why is this and how else could I loop the program?
2)I declared a as an integer and asked the user to type 1,2,3,4 to perform mathematical functions, but when I tried declaring a as a string and searching if a == "PLUS" etc it would throw an error. Is there any mistake in how I approached this?
3)I know this is a bit premature to ask, but instead of writing _________ in the console to separate the loop is there any professional way to add a separator?
im trying to make a program which will tell which key i pressed and then it will print in msgbox, but i cant figure out how to read the key in loops, like i tried getasynkey (imported to my c# console app) with value around -32676 or -32767 i ( i found it on internet) and it only shows the key once, i want to do like while my key is pressed, then it will spam my console with key pressed, is there any way to do it?
Parts of this program are missing. The last few lines are confusing, since the variable 'a' gets incremented then decremented. But there are no loops. I understand that the value of 'a' is passed to 'c' before 'a' is changed in both cases.
But where, and when, do the changes take place? Is the decrement ever processed? Is there a better way to write these lines?
Code: main(){ int a = 21;int b = 10;int c ; c = a++; cout << "Line 6 - Value of c is :" << c << endl ; c = a--; cout << "Line 7 - Value of c is :" << c << endl ; return 0;}
i am trying to write program that prints out full lyrics to 99 bear song. Hoping for explanation or anything
The output would have to look like:
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
My try below:
Code: #include <iostream> using namespace std; int main() { for(int i=99; i>=0 ;i--) cout << i <<""<< " bottles of beer on the wall, "<<i<<" bottles of beer."<<endl; for(int j=98; j>=0 ;j--){ cout <<endl; cout << "Take one down and pass it around," <<j<<" bottles of beer on the wall."<<endl; } return 0; }
N3337 wrote:86) this ensures that a top-level comma operator cannot be reinterpreted as a delimiter between init-declarators in the declaration of __range.
What in the world would be a valid example of when this might occur? (IE one that isn't blatantly misusing the quirks of the language).
This topic can also serve as a review topic on this presentation as well: [URL] .....
I have to make my program display days 1-30 along side numbers increasing by 5 each day beginning with 6 on the first day. I wrote 2 for loops on separate tabs but now I want to know if its possible to combine them into 1.
For loop 1 int day,; for (day = 1; day <=30; day = day + 1)
For loop 2 int candy; for (int candy = 6; candy <=151; candy = candy +5)
I need to make a FOR loop for an array of 5 elements. (array[5]). The loop should pick the positions [1] and [4] and removes the integers positioned in it and the integers next to it should fill in the space like this:
Elements in Array: 23 24 25 26 27
Elements after deletion: 23 25 26 0 0
I'm having a hard time making one ....
Here's the code i tried to make (so far, i keep on failing):
#include<stdio.h> #include<conio.h> int main() { void del(int*, int); int array[5] = {23,24,25,26,27}; int z = 5;
So in class our teacher assigned us a program where we have to use nested for loops to creates triangles. How does the 2nd for loop print more than 1 star? since the for loop will only run the cout 1 time until it gets to the escape sequence, how does it print more than 1 star on a line? this is what is confusing me. I feel like if i can grasp the understanding of that and what the for loops are doing i can finish the rest of this program with ease
#include<iostream> using namespace std; int main()
I'm having trouble trying to get my loop program to display multiples of 4 in rows and columns. My objective is to print multiples of 4 that are less than 100 in a 4 by 4 format.
So far when I write the code I get 4 8 12 16 20 .... 96 all on the same line.
This is what I expect the code to look like if done correctly.
1)I took an integer 2)I try to convert it into binary by storing the remainder by dividing it in 2, in an integer array size of 8(array1) 3)But the digits are in the reverse order, so I reverse them(array 2) 4)When the number is less like 40 or 20 there are no 8 digits/bits 5)So further manipulation of bits i need to pad some other value(say its 2)in the beginning of the array where you will have continuous zero bits.
I want to pad another bit apart from 1 and 0 until you find one. for example say the content of array2 will be 00010111 then i need it to be 22210111.But my method is not working and make the program non responsive.
I have an assignment for class .. It works, the do-while loop isn't working correctly. Once I am doing inputting information for any employee It should ask to continue. It doesn't, It skips that loop and prompts to enter the type of employee again.
#include <iostream> #include <iomanip> using namespace std; int main( ) { char empInput; char continueResponse;