T3st sc0re with name

#include<iostream>
#include<windows.h>
using namespace std;

int main()
{
int tempTest = -1;
int testCount, testAverage;
string name1,name2,name3,name4;

cout << "\n - Enter the Students name: ";
cin >> name1>> name2 >> name3 >> name3;
system("cls");
do {
cout << "Enter the number of test scores to average (up to 100): ";
cin >> testCount;

if (testCount < 1 || testCount > 100)
cout << "INVALID! Number must be between 1 and 100." << endl << endl;
} while (testCount < 1 || testCount > 100);

cout << endl;

for (int i = 1; i <= testCount; i++)
{
do {

cout <<"Input test score " << i << ": " << name1 << " "
<< i << ": " << name2 << " "
<< i << ": " << name3 << " ";

cin >> tempTest;

if (tempTest < 0 || tempTest > 100)
cout << "INVALID! Number must be between 0 and 100." << endl << endl;
} while (tempTest < 0 || tempTest > 100);

cout << endl;

}


cout <<name1 << tempTest << endl
<< name2 <<endl
<<name3 <<endl;

return 0;
}
Last edited on

@iQChange was that really necessary? - nice to see your in a helping mood.


@O/P

Please put your code in code tags.

You have declared name as an integer in testscore that can only hold numeric values. This link may be useful to you: http://www.cplusplus.com/doc/tutorial/variables/

do..while loops: http://www.cplusplus.com/doc/tutorial/control/

Assuming you know arrays/strings...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

	const int maxNames = 4;
	string names[maxNames];
	int scores[maxNames];
	int namesCount = 0; 

	// get the 4 names and scores.
	do	{
		cout << "Enter name " << namesCount + 1 << ": ";
		cin >> names[namesCount];
		cout << "Enter score for " << names[namesCount] << ": ";
		cin >> scores[namesCount];
		namesCount++;
	} while (namesCount < maxNames);

	// ---- rest of your code ----


Feel free to ask questions.
@Softrix I did his program in my computer, even created those classes I would use if could not #include. I could help him, but, come on, what you said to me was really more necessary.

Calling someone a noob because he doesn't know how to do something is normal behaviour? - everyone has to start somewhere, and you were there once remember? - so don't be so harsh with people and just offer some advice, which is the WHOLE point of this forum isn't it?
Noob = newbie. His programs do what he wants, he only must join them. I was going to reply him, but I had no time. Eg.: I'm typing from a smartphone. I said "I don't like to be rude" because I know what would be the reaction. So there we are.
The Beginners forum is by definition going to have questions from newbies/noobs looking for guidance. If you don't have the time or inclination to help, you can just leave the post for someone else who does.

+1 @Wildblue

@ iQChange So if you didn't have anything constructive to add then you shouldn't have even posted. I'm not going to go through an endless debate here so just leave it.
I was trying to help. You made me quit. Congratulations.

I can only assume your replying with childish comments to increase your post count because other than that, they are pointless.

You talk rubbish, "I don't like to be rude, but you're a noob. Come on, you can do it better!" doesn't look to me like you were planning to help, unless my English is not as good as yours...

I see someone has reported your post, its clear I am not the only one who thinks your attitude sucks, now grow up and learn to behave on the forum.

Oh @Softrix, what can you talk about me? I grew up since a long time. Can you understand I was going to reply? I just had no time!
So please, stop sayin' I'm a "child" or I can't behave in this simple forum. Come on guy, please, don't be a pain in the @ss.
Like you, I'm leaving now. Hope we don't have further misunderstoods.
May I ask why you posted a bunch of arbitrary programs with the one you wanted help with? You should only post relevant information in the future; it will make it easier to help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
TESTSCORE
//Jabat, Kiana SKye
//COE113L-A5-17
//TestScore.cpp

#include <iostream> 
using namespace std; 

int main() 
{ 
int testScore1, testScore2, testScore3, testScore4, name;  //a name is a string of characters not an integer
//you should make it a std::string or if you have not learned yet
//a character array (c-string)
double average; 

//you should also initialize all of those variables declared


cout << "Enter names: " <<endl;
cin>>names

cout<<"Enter test score 1: "; 
cin >> testScore1; 

cout << "Enter test score 2:"; 
cin >> testScore2; 

cout << "Enter test score 3:"; 
cin >> testScore3; 


average = (testScore1 + testScore2 + testScore3)/3; 


cout << "Your total average is: " << average << endl; 


return 0; 
}


To wrap it in a do/while loop you will need a new variable for the conditions. Something like:
1
2
3
4
5
6
7
char repeat = 'y'; //since it is initialized we could honestly use a while loop
//and would be safe that it runs at least once

do
{
    //stuff to repeat
} while(repeat == 'y' || repeat == 'Y'); //condition 



[edit]You may find these links helpful for future references: http://www.cplusplus.com/doc/tutorial/
http://www.learncpp.com/
http://www.parashift.com/c++-faq/


Though for this assignment these will help learning control structures:
http://www.learncpp.com/ ~chapter 5:
- http://www.learncpp.com/cpp-tutorial/56-do-while-statements/

http://www.cplusplus.com/doc/tutorial/control/ ~1/3 down the page

You also seem to have used the do/while loop a few other times in your programs shouldn't be too trivial to incorporate it into the one you want it in.[/edit]
Last edited on
This is for our lab I posted it here so I could put this on the hard drive. Sorry for the unnecessary codes. I tried to make one but I failed so
Thanks btw big help
Topic archived. No new replies allowed.