/*hi I'm having problems with my "while ()" apperently it is not taking any action, and it keeps going endless. i need it to stop when the answer is 'n'*/

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream.h>

//---------------------------------------------------------------------------
void main()
{
char pais[20],r;
int i=1,temp=0,ctemp=0,atemp=0,dia=0;
float promt;
clrscr();
        fflush(stdin);
        cout << "desea registrar paises S/N \n";
        cin >> r;
        cout << "indique dias anotados por el pais \n";
            cin >> dia;
        cout << endl;

         while (r='s')
          {
            cout << "\n indique pais de procedencia \n";
            cin >> pais;
                 for (i=1;i<=dia;i++)
                {
                fflush(stdin);
                cout << " indique la temperatura del dia: " << i << ":" ;
                cin >> temp;

                ctemp++;
                atemp=atemp+temp;
                }//for i


            fflush(stdin);
               promt=(atemp/ctemp++);
          cout << "\n el promedio de temperatura en \t" << pais << "\t es:" ;
          cout << promt;
          cout << "\n desea ingresar otro pais? S/N \n";
          cin >> r;

          };
          cout << "tenga un buen dia";
          cout << endl;
          getch();
}

use == instead of = in while

thanks i just notice like a minute ago after i posted, thanks majestics

Unportable code alarm!
You're including conio.h, this isn't a standard library file
iostream.h is not a C header, it's a C++ header, so you posted your code in the wrong forum
Aaargh, the terrible void main() , it's evil, replace it with int main() (read this ).
This is not C code, this is C++ code (this means that you've posted in the wrong forum), consider using new style header files (if your compiler supports it), so:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream.h>

would become:

#include<cstdio>
#include<conio.h>
#include<cstdlib>
#include<cstring>
#include<iostream>

:)

Note: This is definitely (rubbish) C++ code (mixed with C), cout is an object, and C isn't an object oriented language :P

commented: gawd yes, what a mess. i too hate conio. +10

It's pretty much logical your while statement isn't working correctly, if you use the '=' operator in an expression, this means that you're assigning something, it means not that you're comparing something, if you want to compare, you should use the '==' operator so while (r[B]=[/B]'s') would become while (r[B]==[/B]'s') :)

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.