C++ while.. igen...|Programmering / Grafisk formgivning|Forum|Nordichardware

Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
The forums are currently locked and only available for read only access
sp_Feed sp_TopicIcon
C++ while.. igen...
Tovedal
Kommer du hit ofta?
Medlem
Forum Posts: 282
Member Since:
June 29, 2004
sp_UserOfflineSmall Offline
1
January 1, 2005 - 2:15 pm
sp_Permalink sp_Print

jag har problem med följande kod:


#include <iostream>
#include <iomanip>
using namespace std;
main()
{
int dagar_tot, dagar=0;
double lon=0, sam_lon=0.0;
const int manad=30;
cout << "Om hur mÄnga dagar blir du miljonÀr???" << endl
<< "Knappa in din mÄnadslön: "; cin >> lon;
while (sam_lon < 1000000)
{
sam_lon + lon;
dagar++;
}
dagar_tot = dagar * manad;
cout << "Du blir miljonÀr om " << dagar_tot << " dagar dÄ du har exakt "
<< sam_lon << " kronor.";
system("pause");
}

man "hinner" skriva in sin lön men sedan sĂ„ vĂ€grar den gĂ„ in i loopen... 🙁

Kronos
Mina inlÀgg skrivs i binÀr kod
Medlem
Forum Posts: 116
Member Since:
July 4, 2003
sp_UserOfflineSmall Offline
810947
January 1, 2005 - 2:36 pm
sp_Permalink sp_Print

Problemet Àr att du inte kommer ut ur loopen.
Peta in ett = enligt nedan sÄ borde det funka.
Utan det sÄ fortsÀtter sam_lon att vara 0.

     while (sam_lon < 1000000) 
{
sam_lon += lon; // HÀr behövs ett += istÀllet för bara +
dagar++;
}
Tovedal
Kommer du hit ofta?
Medlem
Forum Posts: 282
Member Since:
June 29, 2004
sp_UserOfflineSmall Offline
810960
January 1, 2005 - 2:53 pm
sp_Permalink sp_Print

tack det funka 😀

Chewie
Kommer du hit ofta?
Medlem
Forum Posts: 1516
Member Since:
September 13, 2001
sp_UserOfflineSmall Offline
811324
January 1, 2005 - 9:16 pm
sp_Permalink sp_Print

LÀs din output frÄn kompillatorn.
Detta Àr output frÄn "gcc version 3.2.3".

~/c++/tmp $ g++ -Wall test.cpp -o a

test.cpp:5: warning: ISO C++ forbids declaration of `main' with no type
test.cpp: In function `int main()':
test.cpp:13: warning: statement with no effect

Rad 5: mÄste vara

int main()

Rad 13: Ja dÀr ser du varför det inte fungerar.

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1030
Currently Online:
Guest(s) 189
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Andreas Galistel: 16287
Jonas Klar: 15897
ilg@dd: 10810
Nyhet: 10607
Mind: 10550
Ctrl: 10355
Gueno: 9881
Guest: 9344
Snorch: 8881
Callister: 8468
Newest Members:
PetrbonFU PetrbonFU
Karine Bembry
Dolores Mcdaniels
Anibal McLeish
Francisca Alt
Alfie Everhart
Lester Huitt
Orlando Jorgensen
Mikki Lundgren
Dakota Kozlowski
Forum Stats:
Groups: 11
Forums: 59
Topics: 146630
Posts: 1300967

 

Member Stats:
Guest Posters: 2
Members: 79425
Moderators: 0
Admins: 11
Administrators: nordicadmin, Henrik Berntsson, Anton Karmehed, Carl Holmberg, Joel Oscarsson, Mikael Linnér, Mikael Schwartz, Andreas Paulsson, Nickebjrk, Mattias Pettersson, EmxL