2014-10-09 61 views
1

嘿家伙我一直试图解决这个问题一段时间了。因为我目前在我的大学(Cegep)的第一次会议,所以我是新编程的。 Visual Studio 2012似乎跳过我的代码的一部分,我需要输入1或2在rehaussement = Convert.ToChar(Console.Read()); 它不提示我输入件事我得在调试部分没有任何错误,这里是我的代码:`C#跳过我的代码的一部分

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      //1464649 - Benjamin Lam 
      int nbPhotos; 
      char format; 
      char reponse; 
      char rehaussement; 
      float prix; 

      //Début 

      Console.WriteLine("Entrez le nombre de photos que vous voulez développer :"); 
      nbPhotos = Convert.ToInt32(Console.ReadLine()); 
      Console.WriteLine("Quel format désirez-vous pour les photosÉ Entrez :"); 
      Console.WriteLine("p ou P pour petit format"); 
      Console.WriteLine("g ou G pour grand format"); 
      format = Convert.ToChar(Console.Read()); 
      Console.WriteLine("Désirez-vous un rehaussement pour les photos? Entrez: "); 
      Console.WriteLine("o ou O pour oui"); 
      Console.WriteLine("n ou N pour non"); 
      reponse = Convert.ToChar(Console.Read()); 

      if ((reponse == 'o') || (reponse == 'O')) 
      { 
       Console.WriteLine("Quel type de rehaussement désirez-vous? Entrez"); 
       Console.WriteLine("1 pour noir"); 
       Console.WriteLine("2 pour sepia"); 
       rehaussement = Convert.ToChar(Console.Read()); 
      } 
      else 
      { 
       rehaussement = '0'; 
      } 
      //calcul du total a payer 
      if (nbPhotos < 50) 
      { 
       if ((format == 'p') || (format == 'P')) 
       { 
        prix = (nbPhotos * 0.15f); 
       } 
       else 
       { 
        prix = (nbPhotos * 0.25f); 
       } 

       if (rehaussement == '1') 
       { 
        prix = prix + nbPhotos * 0.75f; 
       } 
       else 
       { 
        if (rehaussement == '2') 
        { 
         prix = prix + nbPhotos * 0.50f; 

        } 

       } 
      } 

      else 
      { 
       if (nbPhotos <= 100) 
       { 
        if ((format == 'p') || (format == 'P')) 
        { 
         prix = nbPhotos * 0.10f; 
        } 
        else 
        { 
         prix = nbPhotos * 0.20f; 
        } 

        if (rehaussement == '1') 
        { 
         prix = prix + nbPhotos * 0.75f; 
        } 
        else 
        { 
         if (rehaussement == '2') 
         { 
          prix = prix + nbPhotos * 0.50f; 
         } 
        } 
       } 
       else 
       { 
        if ((format == 'p') || (format == 'P')) 
        { 
         prix = nbPhotos * 0.08f; 
        } 
        else 
        { 
         prix = nbPhotos * 0.16f; 
        } 
        if (rehaussement == '1') 
        { 
         prix = prix + nbPhotos * 0.50f; 
        } 
        else 
        { 
         if (rehaussement == '2') 
         { 
          prix = prix + nbPhotos * 0.25f; 
         } 
        } 
       } 

      } 

      //affichage de resultat 

      Console.WriteLine("Le nombre de photos développées est " + nbPhotos); 
      if ((format == 'p') || (format == 'P')) 
      { 
       Console.WriteLine("Le format choisi est PETIT"); 
      } 
      else 
      { 
       Console.WriteLine("Le format choisi est GRAND"); 
      } 
      if (rehaussement == '1') 
      { 
       Console.WriteLine("Le rehaussemenet choisi est NOIR et BLANC"); 
      } 
      else 
      { 
       if (rehaussement == '2') 
       { 
        Console.WriteLine("Le rehaussement choisi est SEPIA"); 
       } 
       else 
       { 
        Console.WriteLine("Aucun rehaussement choisi"); 
       } 
      } 
      Console.WriteLine("Le prix à payer est" + prix + (" $")); 
      //Fin 
     } 
    } 
} 

` 我的大多数东西是法语,因为我去法国学院(Cegep)。 希望有人能帮助我解决这个问题。

+1

有你尝试'Console.ReadKey'来代替? – 2014-10-09 23:33:06

+0

我怀疑在控制台上阅读'响应'的上面一行没有阅读你认为正在阅读的内容。 – 2014-10-09 23:37:19

+0

@SteveG它应该。 'Read()'返回输入字符的整型值。 – TyCobb 2014-10-09 23:38:51

回答

1

使用输入行(),而不是阅读():

format = Convert.ToChar(Console.ReadLine()); 
+4

这将如何解决OP的问题?换句话说,使用'ReadLine()'而不是'Read()'的原因是什么? – Tim 2014-10-09 23:38:51

2

尝试更改format = Convert.ToChar(Console.Read());以代替使用ReadLine。 的原因是由于该行为是.Read没有结束输入流 - 按MSDN(见注释部分) http://msdn.microsoft.com/en-us/library/system.console.read(v=vs.110).aspx

+4

这将如何解决OP的问题?换句话说,使用'ReadLine()'而不是'Read()'的原因是什么? – Tim 2014-10-09 23:39:46