User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,583 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,636 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2044 | Replies: 10
Reply
Join Date: Oct 2007
Posts: 9
Reputation: clski1973 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
clski1973 clski1973 is offline Offline
Newbie Poster

help in starting a program

  #1  
Nov 4th, 2007
I have trouble approaching my program assignments. First I write out an algorithm. and work out each part if the program. Then I get nervous. and overwhelmed. with the errors in compliling and such. I have been working on the current assignment several days. And am frustrated and 2nd guessing myself. Feeling very stressed at this point.
advice?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: help in starting a program

  #2  
Nov 4th, 2007
Welcome to the world of programming.

All I can say is: it gets better.

The C++ compiler (especially with the STL) is not a very sympathetic complainer. Show us what you've done: algorithm, code, errors, etc. and we'll help you think your way through it.

Don't feel bad or give up though. You are waaay smarter than that computer (even if it likes to pretend otherwise).
Last edited by Duoas : Nov 4th, 2007 at 3:40 pm.
Reply With Quote  
Join Date: Oct 2007
Posts: 9
Reputation: clski1973 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
clski1973 clski1973 is offline Offline
Newbie Poster

Re: help in starting a program

  #3  
Nov 4th, 2007
I appreciate your thoughts
Currently using diagrams as well. I am trying to approach it as a foreign language. Things make sense in class but once on my own I'm lost. I was doing really well in the beginning.
I work even slower now. the compiler throws me off. I don't continue on anything till all errs are resolved. therfore I havn't gotten very far.
  1. //Cheryl Slivinski
    //due 11/ /05
    //assignment 8
    /*purpose: Write a C++ program that uses strings, reference parameters
    from Chapter and a while loop with a sentinel value*/
    #include <string>
    #include <iostream>
    using namespace std;

    //3 functions
    void test_score (double& test1, double& test2, double& test3);

    int main ()
    {
    string studentName;
    cout<<"Enter student's name or DONE to quit:";
    getline (cin, studentName);
    void test_score(double& test1,double& test2,double& test3);


    return 0;
    }

    //functions
    void test_score (double& test1, double& test2, double& test3)
    {
    cout<<"Enter 3 test scores:";
    cin >> double test1 >> " " >> double test2 >> " " >> double test3;

    return test_score (double& test1, double& test2, double& test3)
    }}
    "a8slivinski.cpp" 32L, 810C written
    [cgregg14@cscilinux2 cgregg14]$ g++ a8slivinski.cpp
    a8slivinski.cpp: In function `void test_score(double&, double&, double&)':
    a8slivinski.cpp:29: syntax error before `>>' token
    a8slivinski.cpp:31: syntax error before `&' token
    [cgregg14@cscilinux2 cgregg14]$
Reply With Quote  
Join Date: Oct 2007
Posts: 9
Reputation: clski1973 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
clski1973 clski1973 is offline Offline
Newbie Poster

Re: help in starting a program

  #4  
Nov 4th, 2007
This problem I started by writing the functions . there are to be 3.
void test_score (as seen on other post)

double average (test 1,test 2, test 3)
{double averagescore;
double totscore;
totscore= test1 +test2 +test3;
averagescore=totscore/3;
returm averagescore;}

void display(studentname, testgrade,averagescore)

{cout << studentname<<endl;
cout<<test1<<test2<<test3<<endl;
cout<<averagescore<<endl;
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: help in starting a program

  #5  
Nov 4th, 2007
Your problems are mostly syntactic, not logical (which is good).

When you declare something you give its type. So, for example, you can declare a double as:
double test1;
You can likewise declare a function as:
void test_score (double& test1, double& test2, double& test3)

You must declare things before you use them so that the compiler knows what type of things they are. According to the above, test1 is a IEEE double floating-point variable, and test_score is a procedure taking three arguments, each one a reference to a double.

That's good. However, once you declare a thing you don't need to remind the compiler what it is when you use it. You did well with the student name: you declared a string variable (studentName) and then used it. You need to do the same thing with test_score:
  1. int main () {
  2. // the student's test scores, obtained using test_score()
  3. double score1, score2, score3;
  4. // the student's name
  5. string studentName;
  6.  
  7. cout<<"Enter student's name or DONE to quit:";
  8. getline (cin, studentName);
  9.  
  10. test_score( score1, score2, score3 );
  11.  
  12. return EXIT_SUCCESS;
  13. }

The type of a thing makes a great deal of difference when programming. In your test_score() function you should remember that its type is "a function taking three references to doubles and returning void (that is, it doesn't return anything)." So it is properly written without a return statement:
  1. void test_score (double& test1, double& test2, double& test3)
  2. {
  3. cout<<"Enter 3 test scores:";
  4. cin >> test1 >> test2 >> test3;
  5. }
You don't need to worry too much about the spaces when using cin.

Your average() and display() functions list the names of each of their arguments, but not the type. Here's a hint:
int add_two_ints( int first, int second ) {
  return (first + second);
  }

Hope this helps.
Last edited by Duoas : Nov 4th, 2007 at 4:29 pm.
Reply With Quote  
Join Date: Oct 2007
Posts: 9
Reputation: clski1973 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
clski1973 clski1973 is offline Offline
Newbie Poster

Re: help in starting a program

  #6  
Nov 4th, 2007
Here is a rough idea of what I'm trying to do

*Write a program that will input a student’s name and 3 test grades.
*It will compute the
average grade for the student,
write out the student’s name,
three test scores,
and average grade.
*The program will also compute the average grade for the class. The program must use the following 3 functions in addition to the main function:
1. a void function to read in the three test scores and pass them back to main as reference parameters.
2. a double function that is passed on the parameter list the three test scores, computes the average and returns the average as the value of the double function.
3. a void function that displays the output data (student’s name, 3 test grades and average grade) with appropriate labels.
The program must use a sentinel controlled loop. The program should continue processing students until and uppercase DONE is entered for the student’s name. When DONE is entered, no test scores are to be read or processed. The program is to end.
*Sample Run where the bold data was entered by the user

Enter student’s name or DONE to quit: John Smith
Enter 3 test scores: 85 90 77
Student: John Smith
Three test scores: 85 90 77
Average grade: 84.00
Reply With Quote  
Join Date: Oct 2007
Posts: 9
Reputation: clski1973 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
clski1973 clski1973 is offline Offline
Newbie Poster

Re: help in starting a program

  #7  
Nov 4th, 2007
Nice to know that I am thinking logically about all this. I'll have to look up IEEE. So there is some reduntancy in my writing. I thought it looked funny. I get confused on when to have a return statement or not. Voids throw me off.
thank you!
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: help in starting a program

  #8  
Nov 4th, 2007
Er, I tend to add a little more information than necessary. IEEE defines the 4-byte and 8-byte floating point number formats used by most minicomputers. In C they are float and double respectively. Don't worry too much about IEEE. Just know that a variable has a specific type, such as int, double, string, bool, void, etc.

THe void type is C and C++'s way of saying that the type of a thing is unknown or undefined. For functions, it means that the function doesn't return anything.
Last edited by Duoas : Nov 4th, 2007 at 4:45 pm.
Reply With Quote  
Join Date: Oct 2007
Posts: 9
Reputation: clski1973 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
clski1973 clski1973 is offline Offline
Newbie Poster

Re: help in starting a program

  #9  
Nov 4th, 2007
After much time this is what I have, still throwing up errors. ANy hints?

//Cheryl Slivinski
//due 11/ /05
//assignment 8
/*purpose: Write a C++ program that uses strings, reference parameters
from Chapter and a while loop with a sentinel value*/

#include <string>
#include <iostream>
using namespace std;

//3 functions
void test_score (double& test1, double& test2, double& test3);
void display(string studentname,double testgrade,double averagescore);
double average (double test1,double test2,double test3);


int main ()
{
sum=0;
enterstudent=0;

double test1, test2,test3;
string studentName;
while (studentname !=DONE)
{
cout<<"Enter student's name or DONE to quit:";
getline (cin, studentName);
//call function
test_score( test1, test2, test3);
display( studentname, testgrade, averagescore)


return 0;
}

//functions
//prompts for info passes it back to main
void test_score (double& test1, double& test2, double& test3)
{
cout<<"Enter 3 test scores:";
cin >>test1 >>test2>>test3;
}
//average functio
double average (test1,test2, test3)
{
double averagescore;
double totscore;
totscore = test1+test2+test3;
averagescore=totscore/3;
return averagescore;
}
//display function
void display(string studentname,double testgrade,double averagescore)
{
cout<<studentname<<endl;
cout<<test1<" "<<test2<<" "<<test3<<endl;
cout<<averagescore<<endl;
}
Reply With Quote  
Join Date: May 2006
Posts: 2,781
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 15
Solved Threads: 229
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: help in starting a program

  #10  
Nov 4th, 2007
What I'd do is program one step at a time. Using your last description,

Start by writing an empty main()
Then write "1. a void function to read in the three test scores and pass them back to main as reference parameters." Test this by outputting the parameters after the return to main() . Get it working before moving on.

Next, add "2. a double function that is passed on the parameter list the three test scores, computes the average and returns the average as the value of the double function." Test until ready in the same way.

etc....
Just take your programs a step at a time. Slow and easy,
Last edited by WaltP : Nov 4th, 2007 at 9:58 pm.
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC