![]() |
| | #1 |
| Registered User Join Date: Nov 2006
Posts: 18
| What is wrong with my code? My first program...... Code: #include <iostream>
using namespace std;
int main() {
double ctemp, ftemp;
cout << "Input a Celsius temp and press Enter: ";
cin >> ctemp;
ftemp = (ctemp * 1.8) + 32;
cout << "Fahrenheit temp is: " << ftemp;
return 0;
}
|
| coreyt1111 is offline | |
| | #2 |
| Registered User Join Date: Nov 2006
Posts: 18
| Oh yea the complier im using is Dev C++ 4.9.9.2 beta if that matters. |
| coreyt1111 is offline | |
| | #3 |
| Registered User Join Date: May 2006
Posts: 894
| You should have read the FAQ. In fact, when you begin and end up on a problem, always read the FAQ because the questions people ask the most often are beginner questions. The simplest solution to solve this problem is to open your program through the console. To do is, click on start and then on run and type 'cmd'. Then, type 'cd directory_of_your_project' and finally 'executable_name' and your program will run just fine. You can also add those two lines at the end of your program (before return 0, which is useless, by the way) : Code: cin.ignore(); cin.get(); =) |
| Desolation is offline | |
| | #4 |
| Registered User Join Date: Nov 2006
Posts: 18
| Thanks Desolation. So your saying if I add those two lines I can run the program without typing cmd etc? Where would I insert those two lines? Thanks |
| coreyt1111 is offline | |
| | #5 |
| Registered User Join Date: Mar 2006
Posts: 726
| At the end. It keeps your program from closing prematurely as it is still stuck waiting for final input from cin.get(). But you should really get into the habit of writing code for the command-line -- that's what the program is made for, to be run from a terminal. When you learn about Unix pipes and redirects, you'll fully grasp what we're trying to tell you here. Until then just take our word for it.
__________________ Code: #include <stdio.h>
void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
/3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
|
| jafet is offline | |
| | #6 |
| Registered User Join Date: Nov 2006
Posts: 18
| why is my book not teaching me to do this if this isnt the correct way? Maybe that comes later in the book? |
| coreyt1111 is offline | |
| | #7 |
| Registered User Join Date: Nov 2006
Posts: 18
| I cant seem to get the run cmd way to work. If my file is named convert.cpp and is located in my documents then would it be mydocuments/convert.cpp ? |
| coreyt1111 is offline | |
| | #8 |
| Registered User Join Date: Nov 2006
Posts: 18
| I got it!! I inserted this code like Desolation said: Code: cin.ignore(); cin.get(); |
| coreyt1111 is offline | |
| | #9 |
| Registered User Join Date: Nov 2006
Posts: 18
| One thing I do notice is I can only enter one number for conversion then when I press enter again it closes, maybe thats why the book didnt tell me those two lines of code? Thanks alot for the help guys. |
| coreyt1111 is offline | |
| | #10 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,319
| Quote:
Quote:
Code: cin.ignore(1000, '\n'); cin.get();
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #11 |
| Registered User Join Date: Feb 2005
Posts: 38
| Try adding: #include <conio.h> at the top and getch(); the line before return. Code: #include <conio.h>
#include <iostream>
using namespace std;
int main() {
double ctemp, ftemp;
cout << "Input a Celsius temp and press Enter: ";
cin >> ctemp;
ftemp = (ctemp * 1.8) + 32;
cout << "Fahrenheit temp is: " << ftemp;
getch();
return 0;
}
|
| MB1 is offline | |
| | #12 |
| Frequently Quite Prolix Join Date: Apr 2005 Location: Canada
Posts: 7,698
| Ctrl-F5? The OP's using Dev-C++, not MSVC! getch() is a bad idea anyway. It's unportable. See the FAQ. http://faq.cprogramming.com/cgi-bin/...&id=1043284385
__________________ dwk Seek and ye shall find. quaere et invenies. "Simplicity does not precede complexity, but follows it." -- Alan Perlis "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra "The only real mistake is the one from which we learn nothing." -- John Powell Other boards: DaniWeb, TPS Unofficial Wiki FAQ: cpwiki.sf.net My website: http://dwks.theprogrammingsite.com/ Projects: codeform, xuni, atlantis, nort, etc. |
| dwks is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Program Plan | Programmer_P | C++ Programming | 0 | 05-11-2009 01:42 AM |
| how do I morse code converting program | panfilero | C Programming | 17 | 10-29-2005 09:16 PM |
| Writing code for a program in C | Sure | C Programming | 7 | 06-11-2005 01:33 PM |
| Where is this program going wrong? | Kirby1024 | C Programming | 8 | 09-01-2002 03:32 AM |
| whats wrong with my code? | Unregistered | C Programming | 2 | 10-31-2001 08:44 PM |