+ 3

Plz explain the code ? And first line output is coming Enter a number0 , I want to remove 0 how can I remove it

#include <iostream> using namespace std; int main() { int num ; int line = 1 ; cout << "Enter a number" << num ; cin >> num ; while (num<=0) { cout << "Number line" << num << endl ; } while (num>0) { cout << "\nLine number" << num ; num -- ; line ++ ; } return 0; }

15th Nov 2022, 11:43 AM
Keshav Karn
Keshav Karn - avatar
24 Answers
+ 2
cout << num; outputs num value. It is still not assigned any value in your code so puts 0 as default. If you don't want to display, don't write it. Just write : cout << "Enter a number : " ; Your first loop is an infinite loop. Remove first loop. Why need it?
15th Nov 2022, 11:58 AM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
+ 2
https://www.w3schools.com/cpp/ This is the best app i used to it
15th Nov 2022, 12:35 PM
Sakshi [Offline ๐Ÿ™ƒ]
Sakshi [Offline ๐Ÿ™ƒ] - avatar
+ 2
Just remove the num variable written in the line with cout<<"enter a number" Here as you haven't declared num to 0 but ide already assumes that num =0 for the very first case, when you take the value from cin then it updates the value, thus as you haven't declared any value and want user to input the value then you should not write num variable in the cout because you haven't took the result from user yet, and thus it's showing 0 in first case
17th Nov 2022, 2:31 AM
Anjana Das
Anjana Das - avatar
+ 1
Thanks you very much Sakshi Mam
15th Nov 2022, 12:14 PM
Keshav Karn
Keshav Karn - avatar
+ 1
#include <iostream> using namespace std; int main() { int num = 1; int number ; int total = 0 ; while (num<=5) { cin >> number ; total+=number ; num++ ; } cout << total << endl ; return 0; } PLZ explain this code also as I don't understand it also
15th Nov 2022, 12:19 PM
Keshav Karn
Keshav Karn - avatar
+ 1
Please learn c++ on Sololearn and try to solve the code step by step and then you don't need to ask again why the code will not run because when you learn the code and practice it then you can solve the code without any error and please don't mind
15th Nov 2022, 12:24 PM
Sakshi [Offline ๐Ÿ™ƒ]
Sakshi [Offline ๐Ÿ™ƒ] - avatar
+ 1
I practice it but after some time I forget the code | How can I manage this problem as I don't remember the code . Also can you plz suggest me some other You tube channel or site where I can learn c++ deeply
15th Nov 2022, 12:29 PM
Keshav Karn
Keshav Karn - avatar
+ 1
Practice the code and make the handwritten notes and then practice in any software when you understand the code don't see the code try to solve by own When you try to solve code by own assume that adding the two numbers Now think how can I add two numbers through c++? Now, I want two numbers store the two numbers in two variables, when you try to logic how can I make then you can solve easily and if you need or confusion or any problem then you get the help on internet hope it's clear to you
15th Nov 2022, 12:34 PM
Sakshi [Offline ๐Ÿ™ƒ]
Sakshi [Offline ๐Ÿ™ƒ] - avatar
+ 1
Keshav Karn Can you add what lines you don't understand? So that it helps to understand your understandings and problem.. May you are trying like but You don't have to understand code by code. You need to understand how the statements inside code works.. Each different blocks are explained in lesson separately.. So revise lessons one more time then try attempt again. Your asked code takes 5 inputs ( from num = 1 to 5 inclusive ) by loop and adds to the total. Finally displays total.
15th Nov 2022, 12:35 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
+ 1
JayaKrishna Thanks you sir for encouraging and motivation
15th Nov 2022, 12:38 PM
Keshav Karn
Keshav Karn - avatar
+ 1
Thank you Sakshi Mam for giving this site I will learn , if any problem come then I will ask to both of you
15th Nov 2022, 12:39 PM
Keshav Karn
Keshav Karn - avatar
+ 1
#include <iostream> using namespace std; int main() { int num ; int line = 1 ; cout<<"Enter a number"; cin >> num ; while (num<=0) { cout << "Number line" << num << endl ; } while (num>0) { cout << "\nLine number" << num ; num -- ; line ++ ; } return 0; }
16th Nov 2022, 2:35 PM
KAUSHIK T K
KAUSHIK T K - avatar
+ 1
Thanks you very much Anjana didi
17th Nov 2022, 2:36 AM
Keshav Karn
Keshav Karn - avatar
+ 1
Keshav Karn 73 YouTube tutorials in a playlist, many of the same lessons as Sololearn: https://youtube.com/playlist?list=PLAE85DE8440AA6B83
17th Nov 2022, 9:02 AM
Scott D
Scott D - avatar
0
I even not understand , plz explain in detail Sir , line number 6 , 13 | and why taking num-- and line++ both
15th Nov 2022, 12:07 PM
Keshav Karn
Keshav Karn - avatar
0
I solve you code and explain the code hope it's clear to you https://code.sololearn.com/c4wjUeV6Jv7L/?ref=app
15th Nov 2022, 12:09 PM
Sakshi [Offline ๐Ÿ™ƒ]
Sakshi [Offline ๐Ÿ™ƒ] - avatar
0
This code is complicated to you if you have not knowledge c++
15th Nov 2022, 12:29 PM
Sakshi [Offline ๐Ÿ™ƒ]
Sakshi [Offline ๐Ÿ™ƒ] - avatar
0
I am learning c++ since 2 days
15th Nov 2022, 12:32 PM
Keshav Karn
Keshav Karn - avatar
0
Plz tell me platforms , You tube channel to learn c++ in deeply ?
15th Nov 2022, 12:32 PM
Keshav Karn
Keshav Karn - avatar
0
c
15th Nov 2022, 3:27 PM
ijabor blossom
ijabor blossom - avatar