| | |
Im new to C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2005
Posts: 3
Reputation:
Solved Threads: 0
I just downloaded Dev-C++ and tried typing code. My first test was
#include <iostream>
using namespace std;
int main()
{
cout << "Enter height in centimeters: ";
int centimeters;
cin >> centimeters;
cout << "Your height in feet " << centimeters << endl;
return 0;
}
But I have discovered that no matter what code I use, if I have the line "cout << "Your height in feet " << centimeters << endl;" then if I press the enter(return) key my program window closes. Can someone please tell me why? Thanks
#include <iostream>
using namespace std;
int main()
{
cout << "Enter height in centimeters: ";
int centimeters;
cin >> centimeters;
cout << "Your height in feet " << centimeters << endl;
return 0;
}
But I have discovered that no matter what code I use, if I have the line "cout << "Your height in feet " << centimeters << endl;" then if I press the enter(return) key my program window closes. Can someone please tell me why? Thanks
It is working as expected. You created a simple console that operates on a command line. When a console application is loaded by double-clicking or otherwise running it from the GUI, Windows creates a temporary console, executes the program, and then closes the console when you press a key after the code has finished executing.
If you want the console to stay open after the program has executed so you can execute other programs, click "Start", click "Run...", type "cmd", click "OK", change the path to the folder where your program is located, and then execute the program.
If you want the console to stay open after the program has executed so you can execute other programs, click "Start", click "Run...", type "cmd", click "OK", change the path to the folder where your program is located, and then execute the program.
Did we help you? Did we miss the point entirely? Update your thread and let us know.
Don't like the answers you are getting?
Did you try searching?
Clean up and optimize Windows 2000/XP
Don't like the answers you are getting?
Did you try searching?
Clean up and optimize Windows 2000/XP
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { char ch = 'j'; while(ch == 'j' || ch == 'J') { cout << "Enter height in centimeters: "; int centimeters; cin >> centimeters; cout << "Your height in feet " << centimeters << endl; cout<<"Wish to enter a new number? Press j or J to continue!\n" "Press any other key to quit!\n"; cin>> ch; } cout<<endl; return 0; }
Hope this helps
•
•
Join Date: Sep 2005
Posts: 3
Reputation:
Solved Threads: 0
ok, your advice was much appreciated
I've now tried to create a calculator that tells you how many days have passed since year 0000, but am having a bit of trouble. can someone please help
thx
also, i'm probably writing more code than i should be, any shortcuts would be very nice too
I've now tried to create a calculator that tells you how many days have passed since year 0000, but am having a bit of trouble. can someone please help
thxalso, i'm probably writing more code than i should be, any shortcuts would be very nice too
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { char ch ='j'; while(ch == 'j' || ch == 'J') { //Declare variables int day; int year; int month; int leapyear; //Get input cout << "Enter year (yyyy): "; cin >> year; if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) leapyear = 1; cout << "Enter month (mm): "; cin >> month; cout << "Enter day (dd): "; cin >> day; { if (leapyear = 1) if (month > 1) day = day + 29; if (leapyear = 0) if (month > 1) day = day + 28; } { if (month = 1) month = (31 * 1); if (month = 2) month = (31 * 1); if (month = 3) month = (31 * 2); if (month = 4) month = (31 * 2) + (30 * 1); if (month = 5) month = (31 * 3) + (30 * 1); if (month = 6) month = (31 * 3) + (30 * 2); if (month = 7) month = (31 * 4) + (30 * 2); if (month = 8) month = (31 * 5) + (30 * 2); if (month = 9) month = (31 * 5) + (30 * 3); if (month = 10) month = (31 * 6) + (30 * 3); if (month = 11) month = (31 * 6) + (30 * 4); if (month = 12) month = (31 * 7) + (30 * 4); } //Do calculations day = (year * 365) + (month) + (day); //Show output cout << "Days since birth of Christ: " << day; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; } cout << endl; return 0; }
Last edited by Dave Sinkula; Sep 29th, 2005 at 10:43 am. Reason: Added [code][/code] tags.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Plz, helping with writing a bit of code. Thanks
- Next Thread: C++
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux 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 test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






