HomeХобби и стильRelated VideosMore From: profgustin

C++ Prompt User to Loop a Program

166 ratings | 26624 views
Demonstrates how to setup a program to loop continuously based on user response. Software used in this demo is Xcode on a Mac. Note that the code for Windows is exactly the same.
Html code for embedding videos on your blog
Text Comments (29)
Link Z (1 month ago)
Thanks had a hard time understanding the while loop concept
Mikhail (1 month ago)
Very Helpful!
Jaleelliot ellLIott (3 months ago)
hamza farooq (4 months ago)
you saved me!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Kelly Clark (4 months ago)
This is exactly what I was looking for. You showed me where I needed to put the while loop when the user is the one that changes the conditional variable.
Jaiman 17 (4 months ago)
May Almighty GOD bless you.....
Thank you so much. may Almighty GOD you......
Nadhir Ghribi (9 months ago)
Nice! Thanks, this was a great video and helped me a lot. Keep going
jerry zurita (1 year ago)
Great video it is very easy to understand what your doing and you explain all the lines for the looping you make thank you!
Carl'z (1 year ago)
i cant use the cout on to the last it said that it is not possible
Alex Tanner (1 year ago)
Thank you so much! very well explained thank you
Brian Weisenritter (1 year ago)
Noice m8
NoYoureWrong I (1 year ago)
so i added this code to my already working algorithm but when  I do scanf("%c", again); it give me an error saying "fornat specifies as char but the argument has type int). could you please tell how to fix this?
UberHero Rian (1 year ago)
Laurethe NoLastName I'd assume it is a C program, so first declare it as char, and place an ampersand '&' before the variable name when asking for input, most probably like scanf("%c", &"variable_name")
Close Friend (1 year ago)
Thank you :)
Special Mango (1 year ago)
I have copied this however when I type anything including y it just goes prompts me with "Press any key to continue . . . " and then closes. Here's my code: https://pastebin.com/EiaTSady
Roger Henthorn (1 year ago)
Couple of issues first off. You really only need to #include <iostream> you also declare the variables multiple1, 2 outside of the loop and again first thing in the loop--this isn't necessary. Take a look at my simple calculator program as an example--you can use this framework as a basis for your loop. //Area Calculator for a rectangle // #include <iostream> int main() { double length = 0; double width = 0; double Area = length * width; char again = 'Y'; char ch = 253; //This assigns the ASCII value of 253 to ch in order to print the upper carrot exponent while (again == 'y' || again == 'Y')//begins while loop { std::cout << "This program computes the area of a given rectangle"; std::cout << "\n\nPlease input a custom width of a rectangle: \n"; std::cin >> width; std::cout << "Please input a custom length of a rectangle: \n"; std::cin >> length; Area = length * width; std::cout << "The custom area of your entered rectangle is: " << Area<<ch; std::cout << "\nWould you like to compute another area? (Y-Yes) (N-No): "; std::cin >> again; } //ends while loop std::cout << "Thanks for using the calculator!"; //exit message return 0; }
Dwiky Kasih (1 year ago)
Thank you very much, i've been searching for this kind a thing and finally got it.
PriceDown (2 years ago)
Ahh so satisfying when you get a answer from the first source. Thanks!
EJ (2 years ago)
Thanks it helps a lot :)
TheAwesome RaZe (2 years ago)
Hej anton
Brandon (3 years ago)
Thanks so much for this, I couldn't figure it out for the life of me! :)
D T (3 years ago)
Thank you for doing this
Philthy Phil (3 years ago)
great video ! i couldnt find this anywhere online. I havent learned bools and stuff so this video was perfect & simple for what i needed. thanks a lot
Jaleelliot ellLIott (3 months ago)
one of the best tutorials are https://www.youtube.com/watch?v=vLnPwxZdW4Y
Edreih Aldana (4 years ago)
thank you very much. this helped out on my program.
Parakletos1st (5 years ago)
you're a legend, miss. Thank you
Swarnkamal Banerjee (5 years ago)
Awesome videos. You elaborate the things so nicely and slowly that even a child can start coding. :) You EARNED a subscriber Prof Gustin. Keep up the work.

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.