Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 31st, 2007, 6:25 PM   #1
Z3nathur
Newbie
 
Z3nathur's Avatar
 
Join Date: Jul 2007
Posts: 17
Rep Power: 0 Z3nathur is on a distinguished road
Post Posting this so you can get an idea of what i'm thinking and overlooking

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;
}
Z3nathur is offline   Reply With Quote
Old Jul 31st, 2007, 6:29 PM   #2
snipertomcat
Programmer
 
snipertomcat's Avatar
 
Join Date: Nov 2005
Location: Spring Valley, CA
Posts: 52
Rep Power: 3 snipertomcat is on a distinguished road
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)
snipertomcat is offline   Reply With Quote
Old Jul 31st, 2007, 6:53 PM   #3
Z3nathur
Newbie
 
Z3nathur's Avatar
 
Join Date: Jul 2007
Posts: 17
Rep Power: 0 Z3nathur is on a distinguished road
hmm need to find a more portable solution for
 system("cls");
Z3nathur is offline   Reply With Quote
Old Jul 31st, 2007, 6:55 PM   #4
Z3nathur
Newbie
 
Z3nathur's Avatar
 
Join Date: Jul 2007
Posts: 17
Rep Power: 0 Z3nathur is on a distinguished road
i meant to use a compilation of the two lines
 
int state;
state = 1;
Z3nathur is offline   Reply With Quote
Old Jul 31st, 2007, 6:57 PM   #5
Z3nathur
Newbie
 
Z3nathur's Avatar
 
Join Date: Jul 2007
Posts: 17
Rep Power: 0 Z3nathur is on a distinguished road
which i have since changed lol. thanks though!
Z3nathur is offline   Reply With Quote
Old Jul 31st, 2007, 8:31 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Jul 31st, 2007, 9:15 PM   #7
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 882
Rep Power: 4 The Dark is on a distinguished road
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;
      ....
will run the first cout over and over and never get to the second cout.
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)
is assigning 1 to state and then checking whether it is non-zero. Change it to:
    while( state == 1)
The Dark is offline   Reply With Quote
Old Aug 1st, 2007, 2:22 AM   #8
Z3nathur
Newbie
 
Z3nathur's Avatar
 
Join Date: Jul 2007
Posts: 17
Rep Power: 0 Z3nathur is on a distinguished road
man, i was NOT expecting this kind of support! thank you guys, seriously.
Z3nathur is offline   Reply With Quote
Old Aug 1st, 2007, 9:18 AM   #9
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 5 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
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

peace_of_mind is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:35 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC