•
•
•
•
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
![]() |
•
•
Join Date: Oct 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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?
advice?
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
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).
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.
•
•
Join Date: Oct 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
- //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]$
•
•
Join Date: Oct 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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;
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;
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
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:
You can likewise declare a function as:
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:
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:
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:
Hope this helps.
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:
C++ Syntax (Toggle Plain Text)
int main () { // the student's test scores, obtained using test_score() double score1, score2, score3; // the student's name string studentName; cout<<"Enter student's name or DONE to quit:"; getline (cin, studentName); test_score( score1, score2, score3 ); return EXIT_SUCCESS; }
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:
C++ Syntax (Toggle Plain Text)
void test_score (double& test1, double& test2, double& test3) { cout<<"Enter 3 test scores:"; cin >> test1 >> test2 >> test3; }
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.
•
•
Join Date: Oct 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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
*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
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
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.
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.
•
•
Join Date: Oct 2007
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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;
}
//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;
}
What I'd do is program one step at a time. Using your last description,
Start by writing an empty
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
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,
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
-- Pearl Williams
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- executing the normal program from linux.rc - different bahaviour (Kernels and Modules)
- C:\Program Files\Common keeps opening on boot (Windows NT / 2000 / XP / 2003)
- Need help starting program. I don't know where to begin. (Pascal and Delphi)
- Need help starting program using vector (C++)
- I just need help starting this program please (C++)
- My Computer is Lagging. (Windows NT / 2000 / XP / 2003)
Other Threads in the C++ Forum
- Previous Thread: Preparing for quiz...some questions
- Next Thread: Linked List Problem



Linear Mode