| | |
the "while (condition) wont work.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2009
Posts: 4
Reputation:
Solved Threads: 0
/*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'*/
c Syntax (Toggle Plain Text)
#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(); }
Last edited by Ancient Dragon; May 31st, 2009 at 12:18 pm. Reason: add code tags
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
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:
would become:

Note: This is definitely (rubbish) C++ code (mixed with C), cout is an object, and C isn't an object oriented language
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:
C++ Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> #include<iostream.h>
C++ Syntax (Toggle Plain Text)
#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
Last edited by tux4life; May 31st, 2009 at 6:03 pm.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
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='s') would become while (r=='s')
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
![]() |
Similar Threads
- Help! My mouse wont work! (USB Devices and other Peripherals)
- Why wont this work!!! (C++)
- Mouse and keyboard wont work (Windows NT / 2000 / XP)
- New Pc parts wont work correctly (Motherboards, CPUs and RAM)
- "Must visit from" javascript wont work in IE... (JavaScript / DHTML / AJAX)
- mouse wont work! (Windows NT / 2000 / XP)
- "Must visit from" javascript wont work in IE... (Site Layout and Usability)
Other Threads in the C++ Forum
- Previous Thread: Help on fatal error :S!!
- Next Thread: Ussue with getline
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






