![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
Batch-2-C++
yay i converted my first batch script to C++
@echo off title Ageinator echo Enter your age... set /p age= echo. echo Enter Years to add... set /p add= echo. cls set /a new=%age%+%add% IF %NEW% GTR 100 SET NEW=DEAD IF %NEW% LSS 1 ECHO You Havent Been Born Yet... & echo. & pause & exit echo In %add% years you will be %new%! echo. pause #include <iostream>
int main()
{
int Age,Add,x;
system("title Ageinator");
std::cout << "Enter your age\n\n";
std::cin >> Age;
std::cout << "Enter years to add\n\n";
std::cin >> Add;
system("cls");
x = Age+Add;
std::cout << "In " << Add << " years you will be " << x << "!\n\n";
system("pause");
return 0;
}
__________________
Hoes telling me to calm down but I'm like fuck that shit!
|
|
|
|
|
|
#2 |
|
Expert Programmer
|
Hey, a start is a start. Good job
![]() |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
Congratulations... Everyone starts from somewhere... Way to go!
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
hey thanks alot
i tryed to put in the if statements but i cant get the first one to work it says "havent been born yet then says the rest of the stuff.. i want it to exit after that #include <iostream>
int main()
{
int Age,Add,x;
system("title Ageinator");
std::cout << "Enter your age\n\n";
std::cin >> Age;
std::cout << "Enter years to add\n\n";
std::cin >> Add;
system("cls");
x = Age+Add;
if (x < 1);
std::cout << "You Havent Been Born Yet...\n\n";
if (x > 100)
std::cout << "In " << Add << " years you will be DEAD!\n\n";
else
std::cout << "In " << Add << " years you will be " << x << "!\n\n";
system("pause");
return 0;
}
__________________
Hoes telling me to calm down but I'm like fuck that shit!
|
|
|
|
|
|
#5 |
|
PFO Founder
![]() ![]() |
just remove the ; after the first if statement like this
#include <iostream>
int main()
{
int Age,Add,x;
system("title Ageinator");
std::cout << "Enter your age\n\n";
std::cin >> Age;
std::cout << "Enter years to add\n\n";
std::cin >> Add;
system("cls");
x = Age+Add;
if (x < 1) // there was a ; after this line which was ending the if statement so the
// part under it was still being done even if the if statement was not true.
std::cout << "You Havent Been Born Yet...\n\n";
if (x > 100)
std::cout << "In " << Add << " years you will be DEAD!\n\n";
else
std::cout << "In " << Add << " years you will be " << x << "!\n\n";
system("pause");
return 0;
}
__________________
BIG K aka Kyle Programming Forums Kyle K Online Please do not PM or email me programming questions. Post them in the forums instead. |
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
If you want it to exit the program completely... you can do this...
if (x < 1)
{
std::cout << "You Havent Been Born Yet...\n\n";
system("pause");
return 0;
}
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Feb 2005
Posts: 112
Rep Power: 4
![]() |
Nice work
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|