I am working on some coursework for university at the moment, and one of the questions asks me to 'write a function that will generate the following pattern using nested looping techniques.'
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.
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 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.
I have been trying to get this piece of code to work but it seems to be running infinitely. What i'm trying to do is that whenever the iterator points to the map element, I check whether the element is 1 or 0. If it is 0, *do something*. But if it isn't, it should not do anything and proceed to the next element in the map.
//infinite loop - not working! for (MapType::iterator p = pwCounter.begin(); p != pwCounter.end(); ++p) { if (p->second.second != 1) {
I have a class with a .h and a .cpp file. (I'm unique!) In the .cpp file, I have a loop and a nested loop. It worked fine when it wasn't in a separate file. Now, the loops will not loop and the value found at the end is some random out of the all park number because no looping took place. I am positive that the conditions and variables are set properly.
I am having a little bit of trouble with what should be a simple part in my code. For some reason it keeps looping the name part of the program and I seem to be passing over the problem in the code.
Here is the code:
#include <iostream> #include <string> using namespace std;
I want to take a starting IP on a local network, and loop through to an ending IP on a local network, pinging all the IP addresses in between. For instance, ping all IP addresses between 192.168.1.1 - 192.168.1.255 (user enters desired starting IP and ending IP in text boxes).
I have the ping functionality working, and i can make it all work with lots of messy string parsing.. but it seems sloppy to me.
I have to split the strings (start and end IP) to get the last octet, then subtract to get the range of IPs. Then loop through, adding 1 to the last octet, and converting back to a string each time.
The C# Ping class can use either a string or an IPaddress for its Send method. If I use IPAddress, I just have to convert it from the text box it originates in, but the adding 1 to the last octet in the loop is a hassle.
Anyway, I guess the only question I have is, if you had to loop through a range of IP addresses, how would YOU do it?
public Job(string ipStartIn, string ipEndIn) { long ip1 = Convert.ToInt64(ipStartIn); long ip2 = Convert.ToInt64(ipEndIn); IPStart = new IPAddress(ip1); IPEnd = new IPAddress (ip2); this.deviceAlive = false;
how to recursively modify my program. The problem I'm hacing is the the program is not looping correctly and also not printing the correct number. I've calculated the payoff correctly, also I've only been able to print the first section of R3. I can't figure out how to loop it to get R2 to stay at 2 then go to 3 after all possiblities of R2 at 2. Enventually, R1 will change to 2 then 3; 3 being the highest number earned. To be mentioned that will be three recursive function loopR1, loopR2, and loopR3 for each column.
The result of the program should look like:
R1 R2 R3 1 1 1 payoff is 1 1 1 2 .......... 1 1 1 3 .......... 1 1 2 1 .......... 1 1 2 2 .......... 1 ... ... ... 3 3 2 .............. 5 this is what I have so far:
#include <stdio.h> #include <stdlib.h> int payOff(int r1, int r2, int r3); void loopR3(int R3, int upto); void loopR2(int R2, int upto);
The glucometer stores the tests and the code just pulls the most recent one, however even if I unplug the glucometer the first if statement keeps repeating and the LED in pin 12 keeps shining. Is it the if statement itself malfunctioning, or is the Arduino storing the data it pulled and just repeatedly plugging that into the if loop?
struct stu_dat //outside main function { int rollno; char name[45], float average;
[Code] ....
No compilation problem.when executing prompt waits for inputting rollno, but, as soon as i enter a char string it keeps looping displaying the "want to enter more data?".i cant understand what is going on,as there is no compilation problem and runs good till i input the name.
I just want my program to run continuously until someone enters 0 to exit it. I tried doing while(x=1) and looping my entire block of code. Also there is a switch one is a for one is a while loop both doing the same function. I have basic error checking and whatnot.
/*This is a program that gets a user to input a starting and ending value. The code then prints the number ie 1 and 5 would be (1,2,3,4,5) and all the squares and cubes. There is a case statement asking weather you want to run it as a for or as a while loop. The choices are case sensitive. */
#include <stdio.h> #include <stdlib.h> #include <math.h>//allows for power and cube function int x; int main(){
Is it possible to create a class that stores (non-const) references to some objects and enables users direct access by using range-based for loops on them?
Code: class container { public: void add(int& value); void remove(int& value); ... }; int main() { container c; for (auto& value:c) { // `value' should be accessible as type `int&' instead of being a pointer, `std::reference_wrapper<int>' or something like that } }
My goal is to create a loop that keeps taking user input over and over until the user doesn't enter anything into 'cin >>', leaves the line blank, and simply presses the ENTER key to move on, at which point the program is supposed to break out of the loop and continue on with the rest of program execution. Something like this:
Code: do { cout << " Enter a name: "; cin >> input1; if (input1.empty())
[Code] ....
As you can see, I've already tried using the empty() function, but that didn't work, the program simply stays in the loop and doesn't break out, no matter how many times I press enter. It just keeps prompting me to enter a name. I've also tried using something like
Code: if (input1 == "")
but that doesnt work either. How do I break out of this loop?
So I've run into the following problem. My goal is to create a loop that keeps taking user input over and over until the user doesn't enter anything into 'cin >>', leaves the line blank, and simply presses the ENTER key to move on, at which point the program is supposed to break out of the loop and continue on with the rest of program execution. Something like this:
do { cout << " Enter a name: "; cin >> input1; if (input1.empty()) {
[Code] .....
As you can see, I've already tried using the empty() function, but that didn't work, the program simply stays in the loop and doesn't break out, no matter how many times I press enter. It just keeps prompting me to enter a name. I've also tried using something like
if (input1 == "")
but that doesn't work either. How do I break out of this loop?
I have chosen C# as our language . Students have to enter a name of a recipe, followed by the number of people it will serve, followed by a list of ingredients for a recipe. This, then, needs to be exported to a text file. This bit I am fine with.
They then have to import the file back into C# and recalculate for a new number of people. This is the bit I am struggling with. The calculation is fine, I can do that. The issue is getting it to loop around each column of data to not only perform a calculation (I have just set it up to multiply by an entered value for now). I have set up a text file with the following data in it:
I have a file that is like the following, with patterns of pipes in it:
Code: ||| || | | | ||| | | | || || ||
I have to consider each row of pipe characters to be in blocks of 3 characters each (e.g. - positions 1-3, then 4-6, etc, etc...) but I have to capture all of the pipes, in sequence, like so:
positions 1-3 for lines 1-3, then positions 4-6 for lines 1-3, etc, etc...
How to get this done besides writing severely redundant control structures like loops, one after the other?
I've been working on this code that should be looking like
1 3 5 3 1 3 5 7 5 3 5 7 9 7 5 3 5 7 5 3 1 3 5 3 1
but mine appears like this
1 3 5 3 1 3 5 7 5 3 5 7 9 7 5 3 3 5 7 9 1 3 1 3 5
This is the code I've got for now, I just don't know which logic I need to fix
int main(){ int r; cout << "Rows?" << endl; cin >> r; for (int i = 1; i <= r; i+=2){ for (int j = i; j <= r+i; j+=2){ cout << j<< " "; } for (int k = i+2; k >= i-1; k-=2){
You pros are once newbies like us. Hoped you might take a little time sharing your expertise. Got freaked out when our teacher gave us this activity, where she haven't taught this to us yet. So this is the activity (LOOPING) :
Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.
OUTPUT must be:
n = 5 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0
if n = 6 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0 6==5==4==3==2==1==0
So I made a simple letter guessing game a while ago and I want to make a simple edit. If the user does not press 'y' or 'n' and instead inputs an invalid letter, I want the printf's in the main function to loop until the user chooses to play or quit.
And I want the choices to show up again at the end of a game. Basically I want it to keep asking if the user wants to play until the user chooses to exit. Here's my code:
#include <stdio.h> #include <time.h> #define MAX_GUESSES 6 void Instructions ( ); //displays instructions, returns nothing char Play ( ); //this functions plays one game, returns W if user wins & L if user runs out of tries
[Code] .....
I'm thinking of making a separate function (like Instructions and Play) ... But how would I link the user input back to the main function?