Click here to Skip to main content
15,880,956 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
please guyz, kindly help me on this serious problem of mine.......i want to return the answer of this variable into my define array in order to iterate through each of them but it i didn't get it right...

C#
a4 = (int)((a / a3) * 70 + a2);
b4 = (int)((b / b3) * 70 + b2);

int[] many = { 0, 0 };
many[0] = a4;
many[1] = b4;

#region
for (int counter = 0; counter < many.Length; counter++)
{
    if (counter >= 70)
    {
        print = "A";
    }
    else if (counter >= 60)
    {
        print = "B";
    }
    else if (counter >= 50)
    {
        print = "C";
    }
    else if (gradeCounter >= 40)
    {
        print = "D";
    }
    else
    {
        print = "F";
    }
}


What I have tried:

C#
//int[] many = { 0, 0 };
            //many[0] = a4;
            //many[1] = b4;
            //#region
          

            //for (int counter = 0; counter < many.Length; counter++)
            //{
            //    if (counter >= 70)
            //    {
            //        print = "A";
            //    }
            //    else if (counter >= 60)
            //    {
            //        print = "B";
            //    }
            //    else if (counter >= 50)
            //    {
            //        print = "C";
            //    }
            //    else if (gradeCounter >= 40)
            //    {
            //        print = "D";
            //    }
            //    else
            //    {
            //        print = "F";
            //    }
            //}
Posted
Updated 29-May-16 20:45pm
v5
Comments
George Jonsson 28-May-16 20:44pm    
You need to explain more what it is you want to do.
The answer of what variable?

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

Your code look buggy, but since it is not an autonomous piece of code, it is not possible to tell for sure.
Update your question with the complete function
Use Improve question to update your question.
 
Share this answer
 
I suspect here

Quote:
for (int counter = 0; counter < many.Length; counter++)
{
if (counter >= 70)
{
print = "A";
}
else if (counter >= 60)
{
print = "B";
}
else if (counter >= 50)
{
print = "C";
}
else if (gradeCounter >= 40)
{
print = "D";
}
else
{
print = "F";
}
}
what you actually mean to do is evaluate your 'many' array in the loop.. so why not this

C#
for (int counter = 0; counter < many.Length; counter++)
{
    if (many[counter] >= 70)
    {
        print = "A";
    }
    else if (many[counter] >= 60)
    {
        print = "B";
    }
    else if (many[counter] >= 50)
    {
        print = "C";
    }
    else if (many[counter] >= 40)
    {
        print = "D";
    }
    else
    {
        print = "F";
    }
}


If thats not what you're looking for, you'll have to do as has been suggested, improve the quality of your question
 
Share this answer
 
Comments
George Jonsson 29-May-16 1:37am    
You are probably right.
+5
Karthik_Mahalingam 29-May-16 4:16am    
good catch
5
ayodejh 7-Jun-16 21:59pm    
thanks so much, this really solve my problem
C#
//It's cleaner to avoid having multiple instances of 'if' 'then' 'else'
 int[] scores = { 38,40,45,50,56,60,65,70,75};
 int[] gradeLevels = { 70, 60, 50, 40 };
 char[] grades = { 'A', 'B', 'C', 'D', 'F' };
 foreach (var score in scores)
    {
      int i;
      for ( i = 0; i < gradeLevels.Length; i++)
          {
            if (score >= gradeLevels[i])
               {
                break;
               }
          }
      Console.WriteLine("Your score was {0}. Your grade  is {1}",score,grades[i]);
    }
    Console.ReadLine();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900