Showing posts with label while. Show all posts
Showing posts with label while. Show all posts

Wednesday, March 15, 2017

C++ Part 24

Working with String - File - While Loop


//NavidPlus.blogspot.com
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main( )
{
   string text;
  fstream inputStream;
   inputStream.open("Website");

   while (inputStream >> text)
{
cout << text << endl;
}

   inputStream.close();
   return 0;
}
// This Program will read all the input while the condition still true.

Input File : Webiste


NavidPlus https://NavidPlus.blogspot.com
NavidPlus@Blogger
Navid Plus is a Tech blog which is focusing on a Science material that I'll be learned every day through my College and job. Most likely blog's posts contain Programming, Security, Networking, Math, and photography. It is a FUN blog.
C Plus Plus @ NavidPlus
INTRO
Intro to C++ Part 1
Intro to C++ Part 2
Intro to C++ Part 3
Intro to C++ Part 4
Intro to C++ Part 5
Intro to C++ Part 6
Intro to C++ Part 7
Intro to C++ Part 8
_________________________________ C++ By NavidPlus.BlogSpot.Com

If you run this Program, you will find the problem !?

Monday, March 13, 2017

C++ Part 22

While loop Example:

#include <iostream>
using namespace std;
int main( )
{
   int numberOfItems, count,
       caloriesForItem, totalCalories;
   cout << "How many items did you eat today? ";
   cin >> numberOfItems;
   totalCalories = 0;
   count = 1;
   cout << "Enter the number of calories in each of the\n"
        << numberOfItems << " items eaten:\n";
   while (count++ <= numberOfItems)
   {
       cin >> caloriesForItem;
       totalCalories = totalCalories + caloriesForItem;
   }
   cout << "Total calories eaten today = "
        << totalCalories << endl;
   return 0;
}

C++ Part 21

While and do-while Statements
A while STATEMENT WITH A SINGLE-STATEMENT BODY



while (Boolean_Expression)
Statement
A while STATEMENT WITH A MULTISTATEMENT BODY
while (Boolean_Expression)
{
Statement_1
Statement_2
.
.
.
Statement_Last
}
A do-while STATEMENT WITH A SINGLE-STATEMENT BODY
do
Statement
while (Boolean_Expression);
A do-while STATEMENT WITH
A MULTISTATEMENT BODY
do
{
Statement_1
Statement_2
.
.
.
Statement_Last
} while (Boolean_Expression);
Do not forget
the final
semicolon.  

Sunday, March 12, 2017

C++ Part 15

Iteration

while: execute a statement as long as some condition is true

do while: similar to while but check condition after executing the statement.

for: execute a statement on every element of some data, or some fixed number of times.



while {loop body}

int count = 0 ;
while ( count < 3) { cout << ” Hello ” << count << endl ; count ++; }

Output :


Hello
Hello
Hello

Digital Design Part 3

4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two different implementations of the same instru...