ok ive got my program to work now but cant get it to ask me if i want it to make a new calculation and i need to do this with a while command i dont what a done code out of you ppl cause its my homework and i want to learn this i just want some tips or hints :P
well my code is:

#include <iostream.h>
#include <conio.h>
int main()
{

int kwh, rate1 = 22, rate2 = 33, rate3 = 40,slut=0;
int base1 = 25, base2 = 35, regning = 0;
char bogstav;
cout << "indtast hvor mange kwh du bruger: ";
cin >> kwh;
if (kwh<=20)
 {
   regning=+rate1*kwh;
   cout << "din regning er på " << regning << " kr." << endl;
 }
else if ((kwh>=21) && (kwh<=40))
 {
   regning=+base1+rate2*kwh;
   cout << "din regning er på " << regning << " kr." << endl;
 }
else
 {
  if (kwh>=41)
  regning=+base2+rate3*kwh;
  cout << "din regning er på " << regning << " kr." << endl;
  cout << "og du skal nok til at skære lidt ned på dit forbrug" << endl;
 }
  getch();
 }

hope some one can help me :P

Well, it's so simple. Enclose this dialog in do-while loop then (after the calculation) ask the user if he/she want to continue then test the answer in trailing while condition.
What's a problem?..

You said that you want to do it through while loop (not 'command' :) ). For that, take some character/BOOL variable and assign to it the value Y/y/TRUE. Then, run the loop with the condition so that it evaluates to be true at the first loop. For other loops, just ask the user if he wants to repeat calculation, and as per the response, either continue the loop or quit.

i will provide a glimpse :

char repeatLoop = 'y';
while ( repeatLoop == 'y' || repeatLoop == 'Y')
{
   // code
   cout << "Do you want to proceed with another calculation ? (y/n)";
   cin   >> repeatLoop;
}

yea knew it was a while loop :P just forgot the word you know :D but thx for the help you2 :D

yea knew it was a while loop :P just forgot the word you know :D but thx for the help you2 :D

:D
it was just in case if you use such words liberally (which a few of my classmates do ;) )
Anyways its fine that you know. So better i conclude. :)

hehe :P. well still cant get it to work i did this;

#include <iostream.h>
#include <conio.h>
int main()
{

int kwh, rate1 = 22, rate2 = 33, rate3 = 40;
int base1 = 25, base2 = 35, regning = 0;
char while = 'j';
while (while == 'j') || (while == 'J')
cout << "indtast hvor mange kwh du bruger: ";
cin >> kwh;
if (kwh<=20)
 {
   regning=+rate1*kwh;
   cout << "din regning er på " << regning << " kr." << endl;
 }
else if ((kwh>=21) && (kwh<=40))
 {
   regning=+base1+rate2*kwh;
   cout << "din regning er på " << regning << " kr." << endl;
}
else
 {
  if (kwh>=41)
  regning=+base2+rate3*kwh;
  cout << "din regning er på " << regning << " kr." << endl;
  cout << "og du skal nok til at skære lidt ned på dit forbrug" << endl;
  cout << "vil du lave en anden udregning ? (j/n)";
   cin  >> while;
 }
   getch();
 }

can anyone help mw abit?

Learn syntax of while loop!

yea guess i'll just go reread it tomorrow but thx you for the help

hehe :P. well still cant get it to work i did this;

#include <iostream.h>
#include <conio.h>
int main()
{

int kwh, rate1 = 22, rate2 = 33, rate3 = 40;
int base1 = 25, base2 = 35, regning = 0;
char while = 'j';
while (while == 'j') || (while == 'J')
cout << "indtast hvor mange kwh du bruger: ";
cin >> kwh;
if (kwh<=20)
 {
   regning=+rate1*kwh;
   cout << "din regning er på " << regning << " kr." << endl;
 }
else if ((kwh>=21) && (kwh<=40))
 {
   regning=+base1+rate2*kwh;
   cout << "din regning er på " << regning << " kr." << endl;
}
else
 {
  if (kwh>=41)
  regning=+base2+rate3*kwh;
  cout << "din regning er på " << regning << " kr." << endl;
  cout << "og du skal nok til at skære lidt ned på dit forbrug" << endl;
  cout << "vil du lave en anden udregning ? (j/n)";
   cin  >> while;
 }
   getch();
 }

this code is not at all acceptable. First of all, no variable of your program can have a name which is a reserved keyword of C++. You have used 'while' as a variable.
Another thing is your while loop's syntax. I should say thats ridiculous.
ANY NUMBER of conditions ,either ANDed or ORed, must be put in a single main parenthesis. Something like this :

while ( condition1 || condition 2 && (condition 3 && condition 4))
{ 
  // code
}

You need to have an extensive study on basics first. :)

hehe thx for the help but found out how how the while loop works my self and also found out it was kinda stupid trying to use while as a variable but a huge thx to you bhoot you where a big help and thx to Sci@phy for telling me not to be so fucking lazy :)

try using the code blocks in the while loop.

{
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.