Oi,
Sou novo no C#. Estava treinando laços e tenho um problema a resolver: Preciso, com um laço for criar um programa no console que leia cinco números, some os cinco e imprima o resultado na tela. Alguem por favor pode ajudar!
Problemas Com Laços
Started By Filipe Campos, 21/12/2006, 14:05
2 replies to this topic
#1
Posted 21/12/2006, 14:05
#2
Posted 22/12/2006, 14:12
For Loop Syntax
Example 1
Suppose you want to reverse the {Customer.Customer Name} string. For example, "City Cyclists" becomes "stsilcyC ytiC".
Example 2
Para registro fica aqui a função nativa
The simplest version is to use the built in function StrReverse:
QUANTO AO CONSOLE...
Exemplo :
Example 1
Suppose you want to reverse the {Customer.Customer Name} string. For example, "City Cyclists" becomes "stsilcyC ytiC".
//Reverse a string version 1
Local StringVar str := "";
Local NumberVar strLen :=
Length ({Customer.Customer Name});
Local NumberVar i;
For i := 1 To strLen Do
(
Local NumberVar charPos := strLen - i + 1;
str := str + {Customer.Customer Name}[charPos]
);
Example 2
//Reverse a string version 2
Local StringVar str := "";
Local NumberVar strLen :=
Length ({Customer.Customer Name});
Local NumberVar i;
For i := strLen To 1 Step -1 Do
(
str := str + {Customer.Customer Name}[i]
);
str
Example 3Para registro fica aqui a função nativa
The simplest version is to use the built in function StrReverse:
//Reverse a string version 3
StrReverse ({Customer.Customer Name})QUANTO AO CONSOLE...
Console.Out.NewLine = "\r\n\r\n";.
Exemplo :
// System.Console.WriteLine
using System;
public class TipCalculator {
private const double tipRate = 0.18;
public static int Main(string[] args) {
double billTotal;
if (args.Length == 0) {
Console.WriteLine("usage: TIPCALC total");
return 1;
}
else {
try {
billTotal = Double.Parse(args[0]);
}
catch(FormatException) {
Console.WriteLine("usage: TIPCALC total");
return 1;
}
double tip = billTotal * tipRate;
Console.WriteLine();
Console.WriteLine("Bill total:\t{0,8:c}", billTotal);
Console.WriteLine("Tip total/rate:\t{0,8:c} ({1:p1})", tip, tipRate);
Console.WriteLine(("").PadRight(24, '-'));
Console.WriteLine("Grand total:\t{0,8:c}", billTotal + tip);
return 0;
}
}
}
/*
Example Output:
---------------
Bill total: $52.23
Tip total/rate: $9.40 (18.0 %)
------------------------
Grand total: $61.63
*/
*************** M ** A ** C ** U ** L ***************
*************************************************
*************************************************
#3
Posted 22/12/2006, 14:50
Thanks for the help.
I´ll try to adapt the code.
Filipe Campos
I´ll try to adapt the code.
Filipe Campos
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)










