-4
I want to make a program that allows you to manipulate and manage information about
Cds that are stored in a text file. The file must save for each CD, the name of the author/group, CD name, year of edition, publisher name, total time (in minutes) and number of tracks.
The if
doesn’t work because?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string line;
int valor;
string input;
string[] names = new string[6];
Console.WriteLine("Escolha:\n1 - adicionar\n2 - Visualizar\n 3 - Sair");
input = Console.ReadLine();
valor = Int32.Parse(input);
if (valor == 1)
Console.WriteLine("Escreva o nome do autor/grupo, nome do CD, ano de edição, nome da editora, total de tempo e número de faixas: ");
for (int i = 0; i < 6; i++)
{
names[i] = Console.ReadLine();
}
StreamWriter SW = new StreamWriter(@"C:\Users\gabri\Desktop\trabalho.txt");
for (int i = 0; i < 6; i++)
{
SW.WriteLine(names[i]);
}
SW.Close();
if (valor == 2)
Console.WriteLine("FICHEIRO .txt: \n");
StreamReader reader = File.OpenText(@"C:\Users\gabri\Desktop\trabalho.txt");
while ((line = reader.ReadLine()) != null)
{
Console.WriteLine(line);
}
Console.ReadKey();
if (valor == 3)
Console.WriteLine("Adeus");
}
}
}
What’s the matter?
– Maniero
Is not running if
– Gabriel Brandao
Explains the behavior you want and what’s going on
– Intruso
I tested it here and it works exactly as expected. The immediately following lines of if (those that have Console.Writeline) are conditioned by the values correctly (after all, when if has no { }, it only holds for the next line). If you expected something different, better [Dit] the question and explain exactly your problem, so that the question can be reopened. By the way, enjoy and tidy up the post if you can, it’s easier to read if you don’t mix different languages, upper and lower, and don’t repeat sentences.
– Bacco