PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] How to count the output of the console

 August 18, 2022     c#, count, output     No comments   

Issue

This is a Grading Marksheet code and I am looking for how the app may count how many times a string (e.g: Grade is A) has been repeated. Thank you! This code sample is the part where I need to count the string from

if (p > 60 && p <= 80)
{
     Console.WriteLine("Grade is A");
}
if (p > 80 && p <= 100)
{
     Console.WriteLine("Grade is A++");
}
Console.ReadLine();

Solution

The idea would be to simply increase a integer variable for each time you print an A.

Example with your Code as Base:

// Use a Variable that you increase in value
// To see how many A were printed
int acount = 0;

// Is number bigger than 60 and smaller or equal to 80
if (p > 60 && p <= 80)
{
    Console.WriteLine("Grade is A");
    acount++;
}
// If the first statement is true the second can't be true anyway
// so use else if so it doesn't have to make usless checks

// Is number bigger than 80 and smaller or equal to 100
else if (p > 80 && p <= 100)
{
    Console.WriteLine("Grade is A++");
    acount++;
}
// Print out result
Console.WriteLine("A was printed: " + acount + " times");
Console.ReadLine();


Answered By - IndieGameDev
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing