Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts
Amazon Auto Links: No products found.
so you can also do
for(a = 1;a <= howMany ; a++){ printf("Loop: %d", a); if(a == maxAmount){ break; } ................. now im just confusing myself.
#include
#include
#include
#include
#include
what will happen if you use a break in a nested for loop… will it kill both loops or just the first?
Have fun with this little piece of code guys:
#include “stdio.h”
#include “stdlib.h”
#include “ctype.h”
#include “string.h”
#include “math.h”
int main()
{
int number, guess, i;
number = 21;
i = 0;
printf(“%sn”, “Hello, I’m thinking of a number, you’re gonna guess it in three tries!”);
while(i++ < 3) { printf("%s %d: ", "Try number", i); scanf("%d", &guess); if (guess > number)
{
printf(“%sn”, “It’s lower than that! Try again!”);
} else if (guess < number) { printf("%sn", "It's higher than that! Try again!"); } else { printf("%s %d %s!n", "Great job! You guessed it in ", i, (i == 1) ? "try" : "tries"); break; } } printf("%sn", "Oops! Game over!"); return 0; }
is it really necassary to have a variable as maxamount=10? cant you just have the for loop be:
for (a=1 ; a=10 ; a++){
how come you don’t need an ampersand right before the a? he did it for howmany, but not a and I don’t get why not.
Awesome as always
so if i want an error check, maybe like if they put something greater than 10, can i make an if statement saying
if (howmany>10) {printf(“please input number between 0 and 1”);}
Thank you much, these tutorials are extremely helpful.
Question: what would I do if I absolutely wanted the user to type a number under 10? Could I include another IF statement under FOR loop specifying that:
if (howmany > 10)
{
printf (“Invalid entry. Please enter a value less than 10.n”);
}
Is this correct?
Why don’t we just use this way ? :
int main()
{
int a,i;
printf(“How many loops?: “);
scanf(“%d”,&a);
for(i=0;i<=a;i++){ printf("%d",i); } }
int a;
int howmany;
int max;
printf(“HOW MANY TIMES LOOPS ?n”);
scanf( “%d”, &howmany);
printf(“What is maximum number ?n”);
scanf( “%d”, &max);
for (a = 1; a <= max; a++){ printf( "%dn",a); if (a==max){ break; } }
can i also do this?
int main ()
{
int a;
int z;
printf(“your number: “);
scanf(“%d”,&z);
for (a=1;a<=z;a++) { printf("%d",a); } return 0; }
Great tutorials! Thanks Bucky! 🙂
Im confused… I input this code and it did not break (aside from that my code wouldnt even run if didn’t take off maxAmount and manually input 10). Can someone please tell me what I did wrong?
#include
#include
#include
Have fun guys 😉
http://pastebin.com/RVDRgrdk
LOL i put max to 1 million and wrote loop 999999 times…….
It took 88 seconds
So we can Also use Letters instead of Number
i had Made one and it Works
#include
#include
int main()
{
char a;
char howMany;
char maxAmount = ‘z’;
printf(“How many times you wanted this loop to loop? “);
scanf(” %c”,&howMany);
for (a=’a’;a<=maxAmount;a++){ printf("%cn",a); if(a==howmany){ break; } } return 0; }
Good one but still this doesn’t show how many you can loop, its basically loop until the number
bro i wanted to create a program which calculates points from every questio.like the question have options: a,b,c,d and each option have different points,and at the end of the process,it totals out and prints the outcome according to diffrernt points….i am really confused on this….can you give me some tips??
For some reason, my code doesn’t work. I’m pretty sure it’s correct:
#include
#include
#include
#include
#include
Really helpful video!
Why can’t I initialize a variable inside of the forloop like > for(int i = 0; i < 5; i++) {} .... It was possible in CS50 ide so I am quite confused atm, does it depend on the ide or what?
error: 1d returned 1 exit status 🙁
It doesn’t break if I enter 10+ value. :/
Here is code I written:
#include
#include
#include
#include
#include
how to define max as infinite ?
Why doesnt it work ?
#include
#include
#include
#include
#include
My program starts printing numbers from 0, not from 1. How can I make it start from 1?
First
1:42 sloop