Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 10-14-2005, 08:34 PM   #1 (permalink)
aaronkupen's Avatar
 
Monster Techie

Join Date: Sep 2005

Location: Boston, MA

Posts: 1,791

aaronkupen is on a distinguished road

Send a message via AIM to aaronkupen Send a message via Yahoo to aaronkupen Send a message via Skype™ to aaronkupen
Default syntax problem

Code:
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <windows.h>

String information()
{
       String sName;
       cout << "Enter your name";
       cin >> sName;

       return sName;
}

int main(int nNumberofArgs, char* pszArgs[])
{

    double dAccumulator;
        do
             {
             cout << "Enter a digit to be added to the accumulator, if you get the accumulator to zero the program will exit";
             double dInput;
             cin >> dInput;

             String sInfo;
             dAccumulator = dAccumulator + dInput;
             sInfo = information();
             cout << sInfo;
             cout << "'s accumulator is now ";
             cout << dAccumulator;
             }
         while (dAccumulator != 0);

    system("PAUSE");
    return 0;
}
Im getting errors with this program, and the only thing I can think of is that im declaring a string variable wrong, it doesnt worth with a capital S or a lower case one. Can you even make a string variable? Any help would be appreciated.
__________________
Lenovo Thinkpad T60
Intel Core 2 Duo T7200 @ 2.00 Ghz
2 GB DDR-2 memory
ATI Mobility Radeon x1400
60 GB 7200 rpm Hard Drive
Windows Vista Business SP1 32 Bit
aaronkupen is offline  
Old 10-14-2005, 09:00 PM   #2 (permalink)
 
Super Techie

Join Date: Jun 2005

Posts: 274

mgoldb2

Default

string would be lower case

inoder to use string you must include #include<string> well that the newer version since you seem to be using the older versions of headers it would either be #include<string.h> or #include<cstring.h> dont remember which.
mgoldb2 is offline  
Old 10-15-2005, 12:35 AM   #3 (permalink)
 
Super Techie

Join Date: Jan 2005

Posts: 295

gab00n

Default

double dAccumulator;

That is the source of your problem, you need to initialize it with a value, in your case 0 would be appropriate.

dAccumulator = dAccumulator + dInput; //Here is the actual bad code

junk = junk + dInput; //See it now
__________________
\"Today\'s scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality.\" Nikola Tesla
gab00n is offline  
Old 10-15-2005, 10:30 AM   #4 (permalink)
aaronkupen's Avatar
 
Monster Techie

Join Date: Sep 2005

Location: Boston, MA

Posts: 1,791

aaronkupen is on a distinguished road

Send a message via AIM to aaronkupen Send a message via Yahoo to aaronkupen Send a message via Skype™ to aaronkupen
Default

alright, those problems helped, but i am still getting errors, and also when I initialize an int variable, do I also have to set a value to it?
__________________
Lenovo Thinkpad T60
Intel Core 2 Duo T7200 @ 2.00 Ghz
2 GB DDR-2 memory
ATI Mobility Radeon x1400
60 GB 7200 rpm Hard Drive
Windows Vista Business SP1 32 Bit
aaronkupen is offline  
Old 10-15-2005, 05:15 PM   #5 (permalink)
 
Super Techie

Join Date: Jan 2005

Posts: 295

gab00n

Default

Let us see what the errors are saying, i'm too lazy to compile your code myself. You only need to initialize the variable if you are using it like you did.

If i say int time, and then input a value from the user and then use it in a calculation i don't have to initialize it because it was initialized by the user before the calculation. But if i am using it in the actual calculation before it has been assigned a value you don't know what is inside it so it will bum out.

string with a lower case s as well, using namespace std should be there and just use int main().
__________________
\"Today\'s scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality.\" Nikola Tesla
gab00n is offline  
Old 10-15-2005, 05:26 PM   #6 (permalink)
 
Super Techie

Join Date: Jan 2005

Posts: 295

gab00n

Default

Code:
 
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;


string information();

int main()
{

    double dAccumulator = 0;
        do
             {
             cout << "\nEnter a digit to be added to the accumulator, if you get the accumulator to zero the program will exit: ";
             double dInput;
             cin >> dInput;

             string sInfo;
             dAccumulator = dAccumulator + dInput;
             sInfo = information();
             cout << sInfo<<endl;
             cout << "'s accumulator is now ";
             cout << dAccumulator;
             }
         while (dAccumulator != 0);

    system("PAUSE");
    return 0;
}

string information()
{
       string sName;
       cout << "\nEnter your name: ";
       cin >> sName;

       return sName;
}
Thats a little better, you should clean it up a bit.
__________________
\"Today\'s scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality.\" Nikola Tesla
gab00n is offline  
Old 10-15-2005, 05:38 PM   #7 (permalink)
aaronkupen's Avatar
 
Monster Techie

Join Date: Sep 2005

Location: Boston, MA

Posts: 1,791

aaronkupen is on a distinguished road

Send a message via AIM to aaronkupen Send a message via Yahoo to aaronkupen Send a message via Skype™ to aaronkupen
Default

Thanks, I understand what you are saying. Also the errors im getting are : line 13- syntax error before {, line 16 syntax error before <, line 17- syntax error before >, line 31 - 'string' undeclared [first use this function]. Those are a few, but im guessing one problem is causing all of these and the rest. (the lines im using are from the original syntax i sent with the information function first)
__________________
Lenovo Thinkpad T60
Intel Core 2 Duo T7200 @ 2.00 Ghz
2 GB DDR-2 memory
ATI Mobility Radeon x1400
60 GB 7200 rpm Hard Drive
Windows Vista Business SP1 32 Bit
aaronkupen is offline  
Old 10-15-2005, 08:35 PM   #8 (permalink)
 
Junior Techie

Join Date: Oct 2005

Posts: 75

darkninja

Default

wow, that looks interesting, what language is that? perl? php?
__________________
<a href="http://www.flashyflashy.net" target="_blank">flashyflashy.net</a>
darkninja is offline  
 
Closed Thread

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
Trackbacks are On
Pingbacks are On
Refbacks are On