-3

I have written my first c# file. Basically what I have is someone puts in different ratings out of 10 (as doubles) for a product for things like taste, texture, presentation etc. I created a weighing system and rating the overall review automatically out of 10. I used Math.Round to round it up to the closest whole number.

I want to display the following line as the following output:

"Overall rating is 5/10 : *****"

Where the number of "*" displayed is automatically displayed as the overall rating calculated (as a whole number).

I have no idea how to do this final bit.

My final output line so far is:

Console.WriteLine("Overall rating is " + ratingRounded + "/10: ");

How would I display the "*" to equally be the same as ratingRounded?

Sorry, I likely did a very bad job explaining it all (I tried my best!).

Thanks in advance.

Me.Name
  • 11,334
  • 3
  • 25
  • 41
lonewolf2288
  • 101
  • 1
  • 1
  • 8

3 Answers3

1

This one's pretty short...

string stars = new String('*', (int)ratingRounded);
Console.WriteLine("Overall rating is " + ratingRounded + "/10: "+stars);
Shark
  • 5,787
  • 3
  • 21
  • 46
0

You can use a loop.

Console.Write("Overall rating is " + ratingRounded + "/10: ");
for(int i=0; i<ratingRounded; i++){
    Console.Write("*");
}
Console.WriteLine();
Tajkia Rahman Toma
  • 472
  • 1
  • 5
  • 16
0

You can use (if ratingRounded is numeric datatype and not string)

Console.WriteLine("Overall rating is " + ratingRounded + "/10: " + new String('*', ratingRounded));
c0d3b34n
  • 516
  • 6
  • 13