Help with console closing down automatically

my first task and I need help as it shuts down immediately after I have answered how do I get it not to shut down automatically? I have onöy read c++ for 3 weeks som im a freshy on this be kind


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  Put the#include <iostream>

using namespace std;

int main()
{ //skriver ner alla variabler vi behöver i början


float deposit; // insättning
float target; // Sparmål
float interest; // Ränta
float balance; // Saldo
int yearCount; // Antal år

while (true) {
cout << "Ange hur mycket du vill s\x84tta in varje \x86r:";
cin >> deposit;
if (deposit > 0) {
break;
}
cout << "Ins\x84ttning per \x86r m\x86ste \x94verstiga 0 kr" << end1;
}
while (true) {
cout << "Ange ditt sparm\x86l:";
cin >> target;
if (target > 0) {
break;
}
cout << "Sparm\x86l m\x86ste \x94verstiga 0 kr" << end1;
}
while (true) {
cout << "Ange r\x84ntesats i procent:";
cin >> interest;
if (interest > 0) {
break;
}
cout << "R\x84ntesatsen m\x86ste \x94verstiga 0 kr" << end1;
}

interest = interest / 100,0f + 1,0f; //startvärden på variablarna
balance = deposit;
yearCount = 1; // yearCount är en int alltså heltal därför skriver vi en etta här

while (balance < target) //Så länge saldot är mindre än sparmålet så:
{

balance *= interest; //multiplicerar totala saldot med räntesatsen
balance += deposit; //lägger till en årlig insättning
yearCount++; // plussar på ett år
} 

cout << balance;
cout << yearCount;
 
cin.get();
return 0;
} code you need help with here.
Last edited on
Your code doesn't compile.

- It's endl (ENDL) not "end1" (end one).

interest = interest / 100,0f + 1,0f;
C++ must use "." (period, full stop) as the decimal separator, not ",".
Last edited on
https://stackoverflow.com/questions/15220861/how-can-i-set-the-decimal-separator-to-be-a-comma

you can do it for input/output but I am not sure you can do it in the code itself (?) -- I have never tried to do this. The I/O support it for the countries that reverse the symbols, but the compilers speak american, as far as I know.

a cin statement, eg

string dummy;
cin << dummy;
will prevent the console from closing


Last edited on
See the 'sticky' thread at the top of this forum ' Console Closing down'
Topic archived. No new replies allowed.