#include <iostream.h>
int main()
{
//declare variables
int score1;
int score2;
int score3;
int result;
//process
result = score1 + score2 + score3;
//display it
cout << "Enter your test scores >" << endl;
cin >> score1;
cin >> score2;
cin >> score3;
cout << "Your overall score is: ";
cout << result;
}
For some reason it doesn't want to add the scores right. I enter 3 scores and it comes out with some random number even though I declared my variables, set result to = score1 + score2 + score3, and I told it to output result.
Am I missing something?
Thanks
[edited by - HTML on October 15, 2003 1:44:51 PM]
Help making simple C++ adding test score program
I am taking the tutorials from www.cplusplus.com and I am on the part with variables, datatypes, and contants. I am trying to use the information they give me to make my own little programs along the way. Here is one that is supposed to add up test scores if you enter 3 of them.
You have to have your values of your scores entered BEFORE you can do calcs on them,... Otherwise it will just use ramdom numbers from some where.
*Yeah,... first post I think I answered right for a question,....*
*Yeah,... first post I think I answered right for a question,....*
you need to set result after you got your 3 scores
for your random numbers, it''s only because when you create a variable, it is assigned an adress in memory, so the value in the variable may be anything that is at this adress in memory so you can never rely on variable to be 0 at creation.
hope that helps
Matt
cout << "Enter your test scores >" << endl;cin >> score1; cin >> score2; cin >> score3; result = score1 + score2 + score3;cout << "Your overall score is: " << result << endl;
for your random numbers, it''s only because when you create a variable, it is assigned an adress in memory, so the value in the variable may be anything that is at this adress in memory so you can never rely on variable to be 0 at creation.
hope that helps
Matt
You need to do your calculation after you have recived the value of the variables. so do
RanBlade
"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...Passion is where great games come from, if you dont live and breathe games you shouldn''t be in the games industry." - Dave Pottinger, Ensemble Studios
[GameDev][C++ Page][Game Tutorials][FreeBSD][HawkNL(Hawk Network Library)][NeHe Productions][Mage Tower Ent-My Site]
cout << "Enter 3 Test Scores\n";cin >> score1;cin >> score2;cin >> score3;result = score1 + score2 + score3;cout << "Your result is " << result;
RanBlade
"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...Passion is where great games come from, if you dont live and breathe games you shouldn''t be in the games industry." - Dave Pottinger, Ensemble Studios
[GameDev][C++ Page][Game Tutorials][FreeBSD][HawkNL(Hawk Network Library)][NeHe Productions][Mage Tower Ent-My Site]
LOL. I''m just wondering, what language supports the thing that he did?
--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..
--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..
XD He means what language supports the calculation of a result before the variables are actually assigned.
Hey Pipo, I know one: F++ for Fictitious.
Hey Pipo, I know one: F++ for Fictitious.
I have another question:
Now I am trying to make it display the percent out of 300 points( assuming all the test were out of 100pts)
I made percent a declared variable, then I did percent = result \ 300( I put it after this time....or did I??)
Thanks
[edited by - HTML on October 15, 2003 3:36:26 PM]
Now I am trying to make it display the percent out of 300 points( assuming all the test were out of 100pts)
#include <iostream.h>int main(){//declare variables int score1; int score2; int score3; int result; int percent; //display it cout << "Enter your three test scores >" << endl; cin >> score1; cin >> score2; cin >> score3; result = score1+score2+score3; cout << "Your overall score is: "; cout << result; cout << " out of 300 points." << endl;// tell what percent you got out of 300pts cout << result; cout << " out of 300 points is a " cout << percent; percent = result \ 300; //the result divided by all pts makes a percent}
I made percent a declared variable, then I did percent = result \ 300( I put it after this time....or did I??)
Thanks
[edited by - HTML on October 15, 2003 3:36:26 PM]
you need to do the calculation after you have been given the variables but you need to do the calculation before you display the result.
RanBlade
"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...Passion is where great games come from, if you dont live and breathe games you shouldn''t be in the games industry." - Dave Pottinger, Ensemble Studios
[GameDev][C++ Page][Game Tutorials][FreeBSD][HawkNL(Hawk Network Library)][NeHe Productions][Mage Tower Ent-My Site]
RanBlade
"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...Passion is where great games come from, if you dont live and breathe games you shouldn''t be in the games industry." - Dave Pottinger, Ensemble Studios
[GameDev][C++ Page][Game Tutorials][FreeBSD][HawkNL(Hawk Network Library)][NeHe Productions][Mage Tower Ent-My Site]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement