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..
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()
The user will enter the number of '*'s on the 1st row (ntop) and then the number of rows forming the trapezoid (nrows). (using <iostream>, cout)
For instance, an inverted trapezoid with 7 '*"s in the 1st row and 3 rows forming the inverted trapezoid looks like: 1******* 2 ***** 3 *** (this pyramid is centered, in case it isnt when its posted). Also, each descending row has two less asteriks than the above row.
I am having trouble with the four loop displaying the number of "*" and " ". I know its a relationship with variables in the for loops, my output is just never doing what i want it to.
THis is the guideline for the for loop:
Use for loops to display the inverted trapezoid. Your outer for loop will iterate the total number of rows times. For each row use one nested for loop to display blanks (the 1st row contains no blanks) and another nested for loop to display the characters '*'.
Heres my for loops so far:
for (i = nrows; i >= 1; i--) { for (j = 0; j >= nrows; j++) { cout << " "; } for (k=ntop; k >= 2; k--) { cout << "*"; } }
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)
For each quarter, calculate and display the beginning principal balance, the interest earned, and the final principal balance for the quarter.For example: The user entered 1000.00 for the beginning principal balance, 5.25 for the interest rate, and 8 for the number of quarters. The output from this part of the program should be similar to the following:
This is a test program that takes a number of arguments from the command prompt and concatenates them into a string object. I was looking into the possibility of using the range-based for loop for this purpose. Can it be done with pointer based arrays? I am mainly doing this because I want to have a firm understanding of range-based for, but also would like to do this with least amount of code possible.
This is my working program:
#include <string> #include <iostream> int main(int argc, char *argv[]) { if (argc > 1) { std::string concatenatedArgs;
[Code] ....
Can I somehow replace my while-loop with a range-based for? I tried the following but the compiler points out that begin and end were not declared in the scope of the range-based for loop.
#include <string> #include <iostream> int main(int argc, char *argv[]) { if (argc > 1) { std::string concatenatedArgs;
Have an assignment due in a few weeks and I'm 99% happy with it My question is is there a method or process for reducing redundant code in nested loops. Ie my code compiles and runs as expected for a period of time and after a few goes it omits a part or prints an unexpected out ext so basically how to find when the redundancy occurs with out posting my code so I can learn for my self?
Write a program to ask a user to input a symbol from the keyboard and to output that symbol in a n X n/2 sized V where n = the width of the V. You must use a loop to process the data
I am stuck at trying to figure out how to do the actual output formatting. This is where I am sitting currently.
string character = ""; int vheight = 0; Console.WriteLine("Enter the character you wish to use for your V: ");
[Code]....
so Im really just a bit stumped on how to get the actual V shape to be formatted..
I wrote this code, and everything was working well, but part of the assignment is that it must include nested loops. Once I added the nested while loop, which is basically an if statement, my life was ruined. I am trying to nest a loop in the code that will basically tell the compiler that if the value "loopVol" were to exceed the value of "final" after adding an increment, to run the program for the "final". How can I do that?
Example:
initial = 10 final = 123 increment = 10
as of now, the program would stop at 120, but I want to nest a loop that will tell the compiler to calculate at the final if this happens.
it occupied too much memory,i wanted to clear them(both outer map and inner map) ,some one told me you just need to call m_mapRISCP.clear(),then the mapSection (inner map) will be cleared automaticly,in other words, m_mapRISCP.clear() will clear both outer map and inner map.
I'm working on a project involving nested classes and structs like this:
Code: class A { public:class B { public:f() {A::C* iCanDoThis; //no errors. iCanAlsoDoThis->root->.... //this also works fine.}private:A::C* iCannotDoThis //this is what I would like to do. Has errors A* iCanAlsoDoThis;};private:struct C {..data..};
C* root;};
Is it possible make a pointer to struct C a private member of class B?
So I think I am having syntactical problem with my code.
Code: int main() { vector<int> ivec; int score; [Code] ....
I get an error from my compiler on the ?10th? line (Nested condition line) that says |19|error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'|
The purpose of the program is to take input and store it in a vector and then change the value to be between 1-6. I made this for the purpose of learning about nested conditional operations.
Note: In this case, the values of x,y and z is integers from 0 to 3 inclusive.
For 3-dimensional space above, actually the code had run through 3 nested "for" loops.
Question: Above code works for 3-dimensional space. How to generalize the code, so that it works also for N-dimensional space, where N is an arbitrary integer?
I have a nested record structure in C++ that contains a FileHeader record, a RecordHeader record and a DataRecord record. The last item is an array of unknown size (at compile time). I have to open a file and read the array size and then create the array.
I have worked on this for some time and can't figure out how to make it work. I know the sample data I am using has 85 records. I insert 85 into the array size and it works fine. But how do I create a dynamic array or define a vector within a nested structure?
1. What is the best (easiest) method to accomplish this (array or vector)? 2. How would it be implemented/how do you add data to it?
PreviousLogRecord.FaultRecord.push_back(field1); // does not work PreviousLogRecord.FaultRecord[recordNumber].field1 = somedata; // works with 85 in array size. struct LogFileHeaderRecordType { QString field1; int field2;
I'm trying to output a pattern using loops. The pattern is a plus symbol made of 3 rows of 5 x's followed by 3 rows of 15 x's and finally 3 rows of 5 x's.
I can get the program to output all 9 rows with 5 x's but I don't know how to do the 3 rows of 15 in the middle. I have tried a while loop and also an if statement but nothing seems to work.
I'm working with CGAL - Computational Geometry Algorithms Library, which is a library of geometry functions declared as several thousand header-only files. When I run a basic program (source code [URL] ) I get this output: [URL]
I have tried switching angle brackets to quotes. I have also started reading up on CMake.
Do I need to walk the dependency tree and add all of those files to my CMakeLists.txt? Or is there a way to tell the compiler to look in subdirectories?
I'm trying to write some naive binary serialization code and wanted to cut down on repetition of logic for serializing/deserializing nested vectors or other STL containers to reduce the chance of typos etc, and thought templates might hold a solution for me.
Is there a way to do something like this? It isn't a big deal for me to just manually write code to serialize my vectors to the needed depth, but it sure would be nice to get this working.
Basically after the 3rd run of the for loop, it encounters a contradiction. I want it to exit right there and then. Instead it continues to run the for loop. What can I do?
You are to create a program using nested looping. Your program is to have a menu asking the user to select which pattern to create and how many rows to use (it should accept 1 to 10 rows and keep the aspect ratio of the pattern). The patterns are 1 - Box, 2 - V, 3 - Inverted V. Note, if I select pattern 1 with 10 rows, the box will have 10 asterisks in the first row.
Okay so i came up with the box but i have been getting stuck at getting the V or inverted V.