When I define the if statement to be if (q==1), and another one to be if (q==2), and I type 2, it still goes to the first statement, as if I typed 1.
if (u==2) {
System.out.println("Hvad har du brug for at regne ud?");
System.out.println("Tryk 1 og enter for stofmængde (n)");
System.out.println("Tryk 2 og enter for molarmasse (g/mol)(M)");
System.out.println("Tryk 3 og enter for samlet masse (m)");
int q = tastatur.nextInt();
if (q == 1); {
System.out.println("Du har valgt at regne stofmængde ud");
System.out.println("Indtast molarmasse og tryk enter");
double molarmasse = tastatur.nextDouble();
System.out.println("Indtast samlet masse og tryk enter");
double masse = tastatur.nextDouble();
double stofmængde = (masse/molarmasse);
System.out.println("Stofmængde =" +masse+ "/" +molarmasse);
System.out.println("Stofmængden =" +stofmængde);}
if (q == 2); {
System.out.println("Du har valgt at regne molarmasse ud");
System.out.println("Indtast stofmængde og tryk enter");
double stof = tastatur.nextDouble();
System.out.println("Indtast samlet masse og tryk enter");
double mass = tastatur.nextDouble();
double mm = (mass/stof);
System.out.println("Molarmasse =" +mass+ "/" +stof);
System.out.println("Molarmasse =" +mm);}}
It seems you should remove ";" after if( ) statement. Get the value of q to check it is 1 or 2. I also suggest to use eclipse due to some sort of bugs exist in netbeans IDE.
Related
I just wrote this code today because my teacher told me to, and well... It's about doing a question of which color I want to of a book (only 3 options, red, green and blue), after that will make a registry of the books (asking the title, author and year of publication), 2 books if I selected red, 3 if I selected green, 4 if I selected blue.
The problem is that when shows the final result, the code ignores all input except the last one, and that input replicates itself, can anyone help me?
Here's the code:
#include<iostream>
using namespace std;
enum Color{
rojo,verde,azul
};
struct libro{
string bookNumber;
Color color;
};
int main(){
string t,au,a;
int color, bookNumber;
cout<<"Seleccione el color del libro, 0. Rojo, 1. Verde, 2. Azul: ";
cin>>color;
switch(color){
case rojo:
bookNumber = 2;
break;
case verde:
bookNumber = 3;
break;
case azul:
bookNumber = 4;
break;
default:
cout << "Opción incorrecta" << endl;
break;
}
for(int i=0;i<bookNumber;i++) {
cout <<"Introduce el titulo del libro " <<i+1<<": "<<endl;
cin>>t;
cout <<"Introduce el autor del libro "<<i+1<<": "<<endl;
cin>>au;
cout <<"Introduce el anio del libro " <<i+1<<": "<<endl;
cin>>a;
}
for(int i=0;i<bookNumber;i++){
cout <<"\t"<<"Titulo: "<<t<<endl;
cout <<"\t"<<"Autor: "<<au<<endl;
cout <<"\t"<<"Anio: "<<a<<endl;
switch(color){
case rojo:
cout<<"\t"<<"Color: Rojo" <<endl; break;
case verde:
cout<<"\t"<<"Color: Verde" <<endl; break;
case azul:
cout<<"\t"<<"Color: Azul" <<endl; break;
}
}
}
And I will leave here an example of what gives when executing:
Seleccione el color del libro, 0. Rojo, 1. Verde, 2. Azul: 2
Introduce el titulo del libro 1:
ABS
Introduce el autor del libro 1:
ABS
Introduce el anio del libro 1:
2003
Introduce el titulo del libro 2:
BCA
Introduce el autor del libro 2:
BCA
Introduce el anio del libro 2:
2005
Introduce el titulo del libro 3:
WWW
Introduce el autor del libro 3:
WWW
Introduce el anio del libro 3:
4444
Introduce el titulo del libro 4:
PPP
Introduce el autor del libro 4:
PPP
Introduce el anio del libro 4:
8788
Titulo: PPP
Autor: PPP
Anio: 8788
Color: Azul
Titulo: PPP
Autor: PPP
Anio: 8788
Color: Azul
Titulo: PPP
Autor: PPP
Anio: 8788
Color: Azul
Titulo: PPP
Autor: PPP
Anio: 8788
Color: Azul
In your loop where you are getting el titulo, el autor, y el anio, you are overwriting the 't', 'au', and 'a' variables each time through the loop. You need to make those variables arrays or vectors.
I got this function in M code to extract data from a webservice, but I get the error:
Expression.Error: Vi kan ikke konvertere en værdi af typen Binary til typen Table.
How do I set the correct datatype for the returnvalue?
(getInvoiceLines as text,FromYear as text,ToYear as text,FromMonth as text,ToMonth as text, ToDay as text) as table =>
let
Kilde = Web.Contents("https://odata.uniconta.com/odata/DebtorInvoiceLines?$filter=Date ge datetime'"&FromYear&"-"&FromMonth&"-01T00:00:00' and Date le datetime'"&FromYear&"-"&FromMonth&"-"&ToDay&"T00:00:00'", [Headers=[Authorization = getInvoiceLines ]])
//Kilde = OData.Feed("https://odata.uniconta.com/odata/DebtorInvoiceLines?$filter=Date ge datetime'"&FromYear&"-"&FromMonth&"-01T00:00:00' and Date le datetime'"&FromYear&"-"&FromMonth&"-"&ToDay&"T00:00:00'", null, [Headers=[Authorization = getInvoiceLines ]])
in
Kilde
Simply remove the return type as table from the function definition.
I have the following text in column A:
<p>De Buddha Lounge Zenju loungeset uit de new kubu wicker Zenju loungeset collectie in de kleurstelling new kubu wicker met zandkleurige kussens. Deze loungeset wordt compleet geleverd inclusief zandkleurige zit- en rugkussens. De Zenju loungeset bestaat uit twee bank elementen van 155x85xH64 cm, een Hoekelement van 85x85xH64 cm en een lounge hocker van 73x73xH40 cm. De totale afmeting van de set is 240x240 cm.</p><p><strong>Details:</strong><br />- Loungeset: 240x240<br />- Sofa L/R:155x85xH64<br />- Hoek: 85x85xH64<br />- Tafel: 73x73xH40</p>
My need is to split the text exactly by:
<p><strong>Details:
so that all the text up to this point is in column B, like this:
<p>De Buddha Lounge Zenju loungeset uit de new kubu wicker Zenju loungeset collectie in de kleurstelling new kubu wicker met zandkleurige kussens. Deze loungeset wordt compleet geleverd inclusief zandkleurige zit- en rugkussens. De Zenju loungeset bestaat uit twee bank elementen van 155x85xH64 cm, een Hoekelement van 85x85xH64 cm en een lounge hocker van 73x73xH40 cm. De totale afmeting van de set is 240x240 cm.</p>
We have a list that has exactly this format and need to split all the columns.
Assuming your data starts from B1 cell of column B. Enter following formula to C1 cell.
=MID(B1,SEARCH("strong",B1)-4,(SEARCH("/strong",B1)-1)-(SEARCH("strong",B1)-4))
For convenience, put this in cell D1:
<p><strong>Details:
Then use this formula, where the text is in cell A1:
=RIGHT(A1; LEN(A1)-SEARCH(D$1;A1)-LEN(D$1)+1)
The result:
</strong><br />- Loungeset: 240x240<br />- Sofa L/R:155x85xH64<br />- Hoek: 85x85xH64<br />- Tafel: 73x73xH40</p>
Documentation:
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_RIGHT_function
https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_SEARCH_function
EDIT:
To get the text before it:
=LEFT(A1, SEARCH("<p><strong>Details:",A1)-1)
Result:
<p>De Buddha Lounge Zenju loungeset uit de new kubu wicker Zenju loungeset collectie in de kleurstelling new kubu wicker met zandkleurige kussens. Deze loungeset wordt compleet geleverd inclusief zandkleurige zit- en rugkussens. De Zenju loungeset bestaat uit twee bank elementen van 155x85xH64 cm, een Hoekelement van 85x85xH64 cm en een lounge hocker van 73x73xH40 cm. De totale afmeting van de set is 240x240 cm.</p>
Please select cells to be truncated, go to Edit > Find & Replace..., and under Search for enter:
<p><strong>Details:(.*)
leave Replace with blank but under More Options check Current selection only and Regular expressions, then Replace All.
This deletes the 'surplus' so you might want to work on a copy (say just copy ColumnA into ColumnB and work on that).
I'm looking for a code to modify list leveling number when I input a specific number on other Sub.
My other Sub reads a number from a paragraph and saves it to an integer.
Then, with that integer I'd need something to do this:
INPUT LIST:
1.5.BLABLABLA
1.5.1.BLIBLIBLI
(SOMEWHERE WILL BE A Paragraph with "14" Text, this to integer)
OUTPUT LIST:
14.5.BLABLABLA
14.5.1.BLIBLIBLI
Well, I'm working OK with this
Sub LimpiaTitulos()
'Normalizador de títulos de nivel determinado(3 en este caso)
ActiveDocument.Repaginate
If ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) > 50 Then
If MsgBox("El documento tiene " & ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) & _
" páginas." & vbCr & "Esta macro no esta pensada para tantas páginas y puede afectar" & vbCr _
& "al rendimiento general del ordenador." & vbCr & "¿Desea realmente ejecutarla?", vbYesNo + _
vbInformation, "Güornin!!!!!") = vbYes Then
GoTo Comienzo
Else
Exit Sub
End If
Else
Comienzo:
Dim ele As List, iTotalParas As Integer, iParacoutner As Integer, p As Paragraph, numeracion As String
iTotalParas = ActiveDocument.ListParagraphs.Count
'Dejamos el primer párrafo con texto, quitando retornos
Borraespacios
Set p = ActiveDocument.Paragraphs(1)
lvl = Int(p.Range.Text)
p.Range.Delete
Borraespacios
'Formato de título
'Formato de título
p.Range.Font.Size = 20
p.Range.Font.Bold = True
p.Range.Font.Italic = False
p.Range.Font.Name = "Arial"
p.OutlineLevel = wdOutlineLevel3
'-------------------------------------------------REGEX----------------------------------------------------
Dim lvl1 As New RegExp, lvl2 As New RegExp
'REGEX primer nivel
lvl1.Pattern = "[0-9]{1,}[.,][0-9]{1,}[.,][0-9]{1,}" 'Admite #.,#.,# - SUPONEMOS JAMAS HABRA #,.#,.#,.#
lvl1.Global = False
'REGEX segundo nivel
lvl2.Pattern = "[0-9]{1,}[.,][0-9]{1,}" 'Admite #.,#
lvl2.Global = False
'Si nos topamos con un nivel 2 de mas caracteres de los deseados, lo tragamos
'-----------------------------------------------FIN REGEX--------------------------------------------------
For iParaCounter = 1 To iTotalParas
' Cogemos el parrafo actual y lo tratamos
Set p = ActiveDocument.ListParagraphs(iParaCounter)
'Metemos el formato de la numeración en un String
numeracion = p.Range.ListFormat.ListString
'Si es de más de 2 carácteres
'If Len(numeracion) > 2 Then
'Filtramos la numeración con la REGEX
If lvl1.test(numeracion) Then
numeración = "1.1.1"
Else
If lvl2.test(numeracion) Then
numeracion = "1.1"
Else
GoTo Siguiente
End If
End If
If p.Range.ListParagraphs.Count = 1 Then
'Borramos el formato y aplicamos el nuevo
p.Range.Select
Selection.ClearFormatting
If Len(numeracion) <= 4 Then
'p.Range.SetListLevel Level:=2
p.OutlineLevel = wdOutlineLevel3
Else
'p.Range.SetListLevel Level:=3
p.OutlineLevel = 10
End If
'Aplicamos lista multinivel de números
p.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries(wdOutlineNumberGallery).ListTemplates(2), _
ContinuePreviousList:=True, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior
'Establecemos el numero del tema
p.Range.ListFormat.ListTemplate.ListLevels(1).StartAt = lvl
'Si el nivel de esquema es 3, aplicamos lista nivel 2
If p.OutlineLevel = 3 Then
p.Range.Font.Name = "Calibri"
p.Range.Font.Size = 14
p.Range.Font.Bold = True
p.Range.Font.Italic = False
'-----SOLO PARA TEST p.Range.Font.ColorIndex = wdBrightGreen
p.Range.SetListLevel Level:=2
'Si el nivel de esquema es 4, aplicamos lista nivel 3
Else
If p.OutlineLevel = 10 Then
p.Range.Font.Name = "Calibri"
p.Range.Font.Size = 12
p.Range.Font.Bold = False
p.Range.Font.Italic = False
'-----SOLO PARA TEST p.Range.Font.ColorIndex = wdBlue
p.Range.SetListLevel Level:=3
End If
End If
End If
'End If
Siguiente:
Next iParaCounter
End If
End Sub
With this, I read a document formatted with a number on the first paragraph and take it for using it as list number. Now I'm thinking, how could I control this in a document with many levels to use?
I have this procedure to add "<OK>" to red colored elements on a list, but it push the elements that are last of its lists
Sub Rojo()
Dim lista As Integer
Dim para As Paragraph
For Each para In ActiveDocument.ListParagraphs
If para.Range.Font.ColorIndex = wdRed Then
para.Range.Text = "<OK> " + para.Range.Text
End If
Next para
The if I have list:
black text
black text
Red Text
Red text
It becomes:
black text
black text
<OK>Red Text
Red text<--This is pushed out of the list
What shoudl I do?
Adde this and elements becomes listed again, but on a new list. Now I would need to push it into the former list. (Hecho is a global boolean)
Sub Rojo()
Dim p As Paragraph
Dim iTotalParas As Integer, iParaCounter As Integer
Comienzo:
If hecho = False Then
iTotalParas = ActiveDocument.Paragraphs.Count
For iParaCounter = 1 To iTotalParas
' For Each p In ActiveDocument.Paragraphs
Set p = ActiveDocument.Paragraphs(iParaCounter)
If p.Range.Font.ColorIndex = wdRed Then
'Mi cosecha
p.Range.Text = "<OK>" + p.Range.Text
If ActiveDocument.Paragraphs(iParaCounter).Range.ListFormat.ListType = 0 Then
ActiveDocument.Paragraphs(iParaCounter).Range.ListFormat.ApplyOutlineNumberDefault
End If
End If
' Next p
Next iParaCounter
hecho = True
'Si ya la hemos ejecutado y volvemos a usarla, avisa antes y controlamos la repetición
Else
If MsgBox("Ya has ejecutado esta macro boniato!" & Chr(13) & "¿Quieres ejecutarla de nuevo?", vbYesNo, "User Input") = vbYes Then
hecho = False
GoTo Comienzo
Else
hecho = True
End If
End If
End Sub
EDITED:::::::::========
Ok, the more I do with this, the more I learn. Ionly had to change p.Range.Text = "" + p.Range.Text to p.Range.InsertBefore("OK")