![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2007
Posts: 17
Rep Power: 0
![]() |
ok don't post a fixed version of this code(my guess is it wouldnt be trying for anyone here) i want to troubleshoot this one myself but i thought i might post it anyways to give you guys an idea of what i'm thinking about. Keep in mind i've only been looking at C++ code for about a day or so and tonight i'm headed out to buy a text for C++ programming. So i'm flying on logic and learning the basics by search.
#include <iostream>
using namespace std;
int main()
{
float age = 0;
float human_age;
int state 1;
int choice2;
char nothing;
cout << "Welcome to Z3nathur's first conversion tool" << endl;
while( state = 1)
cout << "Choose your method of conversion and press enter to continue" << endl;
cout << "1) Dog years -> Human Years" << endl;
cout << "2) Human years -> Dog years" << endl;
cin >> choice2;
if (choice2 = 1)
{
cout << "How old is your dog in dog years?" << endl;
cin >> age;
human_age = age/7;
cout << "Your dog is " << age << " years old in dog years and " << human_age << " years old in human years" << endl;
cin.get();
state ++;
}
if (choice2 = 2)
{
cout << "How old is your dog in human years?" << endl;
cin >> human_age;
age = human_age*7;
cout << "Your dog is " << age << " years old in dog years and " << human_age << " years old in human years" << endl;
cin.get();
state ++;
}
while( state = 2)
{
state = 1;
}
cout << "Press any key to continue";
cin >> nothing;
return 0;
} |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3
![]() |
First off, note that variables in c++ are one word (or words seperated by an underscore rather than a space).
EX: int var char char_variable string this_is_a_string
__________________
if (u=an_asshole) then GOTO (hell) |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jul 2007
Posts: 17
Rep Power: 0
![]() |
hmm need to find a more portable solution for
system("cls"); |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jul 2007
Posts: 17
Rep Power: 0
![]() |
i meant to use a compilation of the two lines
int state; state = 1; |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jul 2007
Posts: 17
Rep Power: 0
![]() |
which i have since changed lol. thanks though!
|
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
To test your code, enter things a careless user might enter instead of the things you expect. For instance, enter 'z' for age.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 882
Rep Power: 4
![]() |
Remember to use braces around multiple statements e.g. (I fixed the indenting):
while( state = 1)
cout << "Choose your method of conversion and press enter to continue" << endl;
cout << "1) Dog years -> Human Years" << endl;
....it should be while( state = 1)
{
cout << "Choose your method of conversion and press enter to continue" << endl;
cout << "1) Dog years -> Human Years" << endl;
...
}While we are looking at the while statement, note that "=" is assignment, whereas "==" is comparison. So your while statement while( state = 1) while( state == 1) |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Jul 2007
Posts: 17
Rep Power: 0
![]() |
man, i was NOT expecting this kind of support! thank you guys, seriously.
|
|
|
|
|
|
#9 |
|
Professional Programmer
|
I think you'll find that if you show that you're working on the problem yourself and always start by posting the code you already have worked on and have a bit of patience that you'll get this level of assistance pretty much every time.
__________________
Amateurs built the ark Professionals built the Titanic |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|