Ok.....thanks for all the help so far....so if I get the numbers as is needed...i'm planning to put them in an inFile....is it ok if I place the numbers in let's say 5 different columns?
Ok.....thanks for all the help so far....so if I get the numbers as is needed...i'm planning to put them in an inFile....is it ok if I place the numbers in let's say 5 different columns?
Thanks Denis for your input...however our professor will not provide us with those numbers...so i guess i'll try to use a random number generator perhaps...
Good day:
We've just commenced our chapter on arrays. The way how it was presented just didn't click to me. The following is the assignment:
" Use a one-dimensional array to solve the following problem. Read in 1000 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read (and printed). Use the smallest possible array to solve this problem."
A few questions:
1. Since it's not practical to type down 1000 numbers in an 'inFile', would it be possible for me to use a randon number generator within the program?
2.Since it's obvious that the numbers will repeat (though dupilcates should not be printed out), I presume that loops will have to be used(according to my instructor)...but how can you use loops when there is no set condition to test statements by? (I hope I stated that correctly).
Any assistance is appreciated. I'll be posting my source code within 24-48 hrs, since i'll need to go read up on this array stuff.
Thanks.
I forgot to do an outFile(output for stunum).....silly of me.....thanks for all the assistance....it's really appreciated.......will be posting an array question on monday and will be sure to have the formatting correct....thanks once again.
inFile >> stunum; // Only one of these, at the start
while (inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term)
Tried it...it never read '10'(# of students)...
with regards to the formatting, i tought i had placed my source-code in the Code Tags...
the read for that new line I added to the inFile, while (inFile>>stunum>>stuname>>Test1>>Test2>>Midterm>>Final>>Term)-with 'stunum' being the variable used for the number of students.
You are correct, just figured it out. Thx, but by any chance did you see why i am not able to read the number of students in the class from the inFile and place it into the outFile? Thanx.
You said that the antivirus programs had completely removed the viruses? I'll check on your log and get back to you.
My inFile is as follows:
10
Gayle 10 8 22 16 22
Brown 7 10 17 11 19
Byles 1 4 21 29 11
Watts 1 2 18 10 17
Walsh 1 5 21 8 18
Ahmed 3 7 16 14 14
Ellis 8 9 20 30 23
Silny 10 10 25 28 21
Simms 8 3 22 24 25
Kenez 5 4 23 22 11
----------------------------------------------------------------------------------------------------------------------------
My source code is as follows:
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int stunum;//# of students in the class
string stuname;// Name of the student
int Test1;//score for test 1
int Test2;//score for test 2
int Midterm;//score for midterm
int Final;//score for final
int Term;//score for term project
int NumA = 0;//# of A's
int NumB = 0;//# of B's
int NumC = 0;//# of C's
int NumF = 0;//# of F's
ifstream inFile;
ofstream outFile;
inFile.open ("ClassData.dat");
outFile.open ("ClassOutput");
while (inFile>>stunum>>stuname>>Test1>>Test2>>Midterm>>Final>>Term)//variables for student info
{
int gradeAvg= Test1 + Test2 + Midterm + Final + Term;
if(gradeAvg>=90)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"A"<<endl;
NumA++;
}
else if (gradeAvg>=80)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"B"<<endl;
NumB++;
}
else if (gradeAvg>=70)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"C"<<endl;
NumC++;
}
else if (gradeAvg<70)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"F"<<endl;
NumF++;
}
}
outFile<<"A's="<<setw(2)<<NumA++<<endl;
outFile<<"B's="<<setw(2)<<NumB++<<endl;
outFile<<"C's="<<setw(2)<<NumC++<<endl;
outFile<<"F's="<<setw(2)<<NumF++<<endl;
outFile<<"The number of students in the class"<<setw(2)<<stunum<<endl;
inFile.close();
outFile.close();
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------------------------
I can't see what's the problem....the output file comes out like this:
Gayle 78 C
A's= 0
B's= 0
C's= 1
F's= 0
-------------------------------------------------------------------------------------------------------------------------------------------------
However, when i remove the variable 'stunum' from my source code-it works …
where in my inFile can I put '10', number of students to have the outFile say: There are 10 students in the class'. I tried placed it there, but it messed up my if/else statements.
ensure that your driver's are ok for that hardware.
:-O :$ ....thanks for the help....simple mistake...will be posting an array's question in a few days.
My latrest Code:
----------------------------------------------------------------------------------
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int stunum;//# of students in the class
string stuname;// Name of the student
int Test1;//score for test 1
int Test2;//score for test 2
int Midterm;//score for midterm
int Final;//score for final
int Term;//score for term project
int NumA = 0;//# of A's
int NumB = 0;//# of B's
int NumC = 0;//# of C's
int NumF = 0;//# of F's
ifstream inFile;
ofstream outFile;
inFile.open ("ClassData.dat");
outFile.open ("ClassOutput");
while (inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term)//variables for student info
{
int gradeAvg= Test1 + Test2 + Midterm + Final + Term;
if(gradeAvg>=90)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"A"<<endl;
}
else if (gradeAvg>=80)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"B"<<endl;
}
else if (gradeAvg>=70)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"C"<<endl;
}
else if (gradeAvg<70)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"F"<<endl;
}
}
outFile<<NumF++;
outFile<<NumC++;
outFile<<NumB++;
outFile<<NumA++;
inFile.close();
outFile.close();
return 0;
}
----------------------------------------------------------------------------------
This program prints four zeros. Also, if i wanted it to print the number of students in the class, I'd have to include '10' in my inFile correct?
I've placed the counters after the loop...it pretty much prints four zeros, because that was the initial value being declared for them. How can I fix that?
You also need to be careful of some hHoax emails that can allow somemalwares to piggy-back onto your system and also keyloggers. I reccm getting a software which prevents against key-loggers.
In addition to viruses, you should check your PC (just as precaution) for Trojan's, spyware, malware,adware, worms ect...With regards to cleaning the registry, several softwares can be found @ www.cnet.com/www.download.net....My personal recommendation for your registry are Reg-Soft and X Soft-Spy to better protect your computer.
The virus may have affected your registry...you may need to reset/clean your windows registry files.
If i alter the program, by placing the counters after the braces...then it tells me that my if/else statements aren't ok.
hhhmmm. Did you mean something like this:
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int stunum;//# of students in the class
string stuname;// Name of the student
int Test1;//score for test 1
int Test2;//score for test 2
int Midterm;//score for midterm
int Final;//score for final
int Term;//score for term project
int NumA = 0;//# of A's
int NumB = 0;//# of B's
int NumC = 0;//# of C's
int NumF = 0;//# of F's
ifstream inFile;
ofstream outFile;
inFile.open ("ClassData.dat");
outFile.open ("ClassOutput");
while (inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term)//variables for student info
{
int gradeAvg= Test1 + Test2 + Midterm + Final + Term;
if(gradeAvg>=90)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"A"<<endl;
}
outFile<<NumA++;
else if (gradeAvg>=80)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"B"<<endl;
}
outFile<<NumB++;
else if (gradeAvg>=70)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"C"<<endl;
}
outFile<<NumC++;
else if (gradeAvg<70)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"F"<<endl;
}
outFile<<NumF++;
}
inFile.close();
outFile.close();
return 0;
}
If i place the counters after the loop...it pretty much prints four zeros, because that was the initial value being declared for them.
Also, how could i get the program to inform the user of the number of student's in the class? I've placed the number '10' in my inFile, but it messes everything else up...where in my inFile/source code should I put the variable 'stunum' for the number of students?
Ok, i got the mathematical part of it and have made the corrections so i'm now able to get the numeric average printed out. However, with regards to the tally of the different letter grades, my source code is as below:
----------------------------------------------------------------------------------
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int stunum;//# of students in the class
string stuname;// Name of the student
int Test1;//score for test 1
int Test2;//score for test 2
int Midterm;//score for midterm
int Final;//score for final
int Term;//score for term project
int NumA = 0;//# of A's
int NumB = 0;//# of B's
int NumC = 0;//# of C's
int NumF = 0;//# of F's
ifstream inFile;
ofstream outFile;
inFile.open ("ClassData.dat");
outFile.open ("ClassOutput");
while (inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term)//variables for student info
{
int gradeAvg= Test1 + Test2 + Midterm + Final + Term;
if(gradeAvg>=90)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"A"<<endl;
outFile<<NumA++;
}
else if (gradeAvg>=80)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"B"<<endl;
outFile<<NumB++;
}
else if (gradeAvg>=70)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"C"<<endl;
outFile<<NumC++;
}
else if (gradeAvg<70)
{
outFile<<stuname<<setw(5)<<gradeAvg<<setw(5)<<"F"<<endl;
outFile<<NumF++;
}
}
inFile.close();
outFile.close();
return 0;
}
----------------------------------------------------------------------------------
My outFile comes out like this, i thought that the counter would automatically do the tally as a whole and not for each individual letter grade...Thanks.
ok thanks for your help....the counter though-isn't working...when I compile the program it doesn't tell me the number of “A”s, “B”’s, “C”’s and “F”’s assigned. Also, in addition to the letter grades, how can i get the program to also show the numeric grade average after it's calculated(average)? Thanks.
My inFile contains the following:
----------------------------------------------------------------------------------
Isaacs 10 8 22 16 22
Brown 7 10 17 11 19
Marley 1 4 21 29 11
Holt 1 2 18 10 17
Washington 1 5 21 8 18
Hammond 3 7 16 14 14
Ellis 8 9 20 30 23
Spear 10 10 25 28 21
Wilson 8 3 22 24 25
Bolo 5 4 23 22 11
----------------------------------------------------------------------------------
My outFile(which is going crazy) contains the following:
----------------------------------------------------------------------------------
CF
F
F
F
F
AABF
---------------------------------------------------------------------------------
My source code contains the following:
----------------------------------------------------------------------------------
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int stunum;//# of students in the class
string stuname;// Name of the student
int Test1;//score for test 1
int Test2;//score for test 2
int Midterm;//score for midterm
int Final;//score for final
int Term;//score for term project
int NumA = 0;//# of A's
int NumB = 0;//# of B's
int NumC = 0;//# of C's
int NumF = 0;//# of F's
ifstream inFile;
ofstream outFile;
inFile.open ("ClassData.dat");
outFile.open ("ClassOutput");
while (inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term)//variables for student info
{
int gradeAvg= Test1 + Test2 + Midterm + Final + Term;
if(gradeAvg>=90)
{
NumA++;
outFile<< "A";
}
else if (gradeAvg>=80)
{
NumB++;
outFile<< "B";
}
else if (gradeAvg>=70)
{
NumC++;
outFile<< "C";
}
else if (gradeAvg<70)
{
NumF++;
outFile<<"F"<<endl;
}
}
inFile.close();
outFile.close();
return 0;
---------------------------------------------------------------------------------
Almost there guys:confused: A …
I see it now....I've made the necessary corrections to my program including the placement of the {}....the last problem is where to place the two follwing statements:
'int gradeAvg= Test1 + Test2 + Midterm + Final + Term' in relation to 'while (inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term)'.
do you mean the hard-disk(hard-drive) or CD/DVD's?
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int stunum;//# of students in the class
string stuname;// Name of the student
int Test1;//score for test 1
int Test2;//score for test 2
int Midterm;//score for midterm
int Final;//score for final
int Term;//score for term project
int NumA = 0;//# of A's
int NumB = 0;//# of B's
int NumC = 0;//# of C's
int NumF = 0;//# of D's
int gradeAvg= Test1 + Test2 + Midterm + Final + Term;
ifstream inFile;
ofstream outFile;
inFile.open ("ClassData.dat");
outFile.open ("ClassOutput");
while (inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term)//variables for student info
if(gradeAvg>=90)
{
NumA++;
outFile<< "A";
}
else if (gradeAvg>=80 || 79<gradeAvg)
{
NumB++;
outFile<< "B";
}
else if (gradeAvg>=70 || 69<gradeAvg)
{
NumC++;
outFile<< "C";
}
else if (gradeAvg<70)
{
NumF++;
outFile<<"F"<<endl;
}
inFile.close();
outFile.close();
return 0;
}
----------------------------------------------------------------------------------
When I compile it says: The variables Test1, Test2, Midterm, Final and Term are being used without being defined...I gess it has to do with my 'int gradeAvg= Test1 + Test2 + Midterm + Final + Term' in relation to 'while (inFile>>stuname>>Test1>>Test2>>Midterm>>Final>>Term)'...So where should i place these terms so it goes through? thx
I've fixed my inFile....so it does show the correct grade now...but how do i get the program to show the names of the students and tally all the A's, B's, C's and F's? I'm pretty sure it wouldn't be a counter because we aren't receiving any input from the user? Thx.
my varaible 'stunum' refers to the # of students in the class
I have removed the semi-colons as was suggested....as u can see that i've placed error log in the event that the program hasn't read any values from my input file. However, the problems that i listed before are still there. I've also changed my conditional staements. I can't see where i'm going wrong and how to get the name to the output file....thanks.
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int stunum;//# of students in the class
int stuname;// Name of the student
int Test1;//score for test 1
int Test2;//score for test 2
int Midterm;//score for midterm
int Final;//score for final
int Term;//score for term project
ifstream inFile;
ofstream outFile;
inFile.open ("ClassData.dat");
outFile.open ("ClassOutput");
inFile>>Test1>>Test2>>Midterm>>Final>>Term;//variables for student info
int gradeAvg= Test1 + Test2 + Midterm + Final + Term;//All semester grade of students
if(!inFile &&! outFile)
cout<<"You have an error"<<endl;
else if(gradeAvg>=90 && 89<gradeAvg)
outFile<< "A";
else if (gradeAvg>=80 && 79<gradeAvg)
outFile<< "B";
else if (gradeAvg>=70 && 69<gradeAvg)
outFile<< "C";
else if (gradeAvg<70)
outFile<< "F"<<endl;
inFile.close();
outFile.close();
return 0;
}
----------------------------------------------------------------------------------
A few problems guys:
1. The program should then calculate the student’s average and assign him/her a letter grade (“A” for 90-100; “B” for 80-89; “C” for 70-79; and “F” for 69 and below). Finally, for each student, the program should print, to output file, his/her name, average, and grade. As you can see from my inFile, it looks like they compiler is reading the data, but if you look at my values for in the first line...mathematically, they add up to "78". So why does it output "B" instead of "C"?
2.It's apparent that the program is reading the data, but how would I also get the program to read the names of the student's in my inFile...i.e. Isaacs, Marley...ect....
3. How can i get the the program should print a summary …
Is your internet firewall also affected by group policy...if so,you can reset it.
When i revert back to my old if-else....it print's "F" rather than "C"...
The source code is as follows:
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int stunum;//# of students in the class
int stuname;// Name of the student
int Test1;//score for test 1
int Test2;//score for test 2
int Midterm;//score for midterm
int Final;//score for final
int Term;//score for term project
ifstream inFile;
ofstream outFile;
inFile.open ("ClassData.dat");
outFile.open ("ClassOutput");
inFile>>stunum>>stuname>>Test1>>Test2>>Midterm>>Final>>Term;//variables for student info
int gradeAvg= Test1 + Test2 + Midterm + Final + Term;//All semester grade of students
if(gradeAvg>=90)
cout<< "A";
else if (gradeAvg>=80 || gradeAvg<90)
cout<< "B";
else if (gradeAvg>=70 || gradeAvg<80)
cout<< "C";
else if (gradeAvg>=60 || gradeAvg<70)
cout<< "F"<<endl;
inFile.close();
outFile.close();
return 0;
}
My inFile is:Isaacs; 10; 8; 22; 16; 22;
Brown; 7; 10; 17; 11; 19;
Marley; 1; 4; 21; 29; 11;
Holt; 1; 2; 18; 10; 17;
Washington; 1; 5; 21; 8; 18;
Hammond; 3; 7; 16; 14; 14;
Ellis; 8; 9; 20; 30; 23;
Spear; 10; 10; 25; 28; 21;
Wilson; 8; 3; 22; 24; 25;
Bolo; 5; 4; 23; 22; 11;
---------------------------------------------------------------------------------
My source is is:
[TEX]#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int stunum;//# of students in the class
int stuname;// Name of the student
int Test1;//score for test 1
int Test2;//score for test 2
int Midterm;//score for midterm
int Final;//score for final
int Term;//score for term project
ifstream inFile;
ofstream outFile;
inFile.open ("ClassData.dat");
outFile.open ("ClassOutput");
inFile>>stunum>>stuname>>Test1>>Test2>>Midterm>>Final>>Term;//variables for student info
int gradeAvg= Test1 + Test2 + Midterm + Final + Term;//All semester grade of students
if(gradeAvg>=90)
cout<< "A";
else if (gradeAvg>=80 || gradeAvg<90)
cout<< "B";
else if (gradeAvg>=70 || gradeAvg<80)
cout<< "C";
else if (gradeAvg>=60 || gradeAvg<70)
cout<< "F"<<endl;
inFile.close();
outFile.close();
return 0;
}[/TEX]
----------------------------------------------------------------------------------
A few problems guys:
1. The program should then calculate the student’s average and assign him/her a letter grade (“A” for 90-100; “B” for 80-89; “C” for 70-79; and “F” for 69 and below). Finally, for each student, the program should print, to output file, his/her name, average, and grade. As you can see from my inFile, it looks like they compiler is reading the …
if(gradeAvg>=90)
cout<< "A";
else if (gradeAvg>=80)
cout<< "B";
else if (gradeAvg>=70)
cout<< "C";
else if (gradeAvg>=60)
cout<< "D";
else
cout<< "F";
In the above code....what I'm trying to get is a program to calculate the student’s average and assign him/her a letter grade (“A” for 90-100; “B” for 80-89; “C” for 70-79; and “F” for 69 and below)....As ii is.....if there is a grade that both fits the criteria of being above 70 and 80...it would print A, B and C....correct. Any help is appreciated.
Got it.....thanks for all assistance-finally figured it all out. not alot of good c++ instructors/professors out there....thanks.
I have placed the guess++; within the loop and it works, just now gottoa work on the program keeping a tallie as to much much times it prints out "Your number was too high-please try again!"vs "Your number was too low-please try again!".
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <string>
using namespace std;
int main()
{
srand ( static_cast<unsigned int> ( time ( 0 ) ) );
int randNum = rand() % 100 + 1;
int num = 0;
int wins = 0;
int losses = 0;
int guess=0;
string uname;
cout<<"Please enter your name: ";
getline ( cin, uname );
cout<< uname <<'\n';
cout<<"Welcome to the Random Number Guessing Game!!\n";
{
do
{
// Loops until user finds the number
cout <<uname<<" "<<"please enter your choice between (#1 - 100): ";
cin >> num; // User's input of guessed number
guess++;
if (num < randNum) // If num is < than the random number, inform player to try again.
cout <<uname<<" "<<"Your number was too low-please try again!";
else
if (num > randNum) // If num is > than the random number, inform player to try again.
cout<<uname<<" "<<"Your number was too high-please try again!";
else
break;
} while (num != randNum);
cout<<uname<<endl;
cout<<" "<< "Excellent Job!! Your number is correct!!"<< endl;//Informs if the player is successfull
cout << "Your total wins: " << wins;//Display the user's score at the end of the program
cout << " Your total losses: " << losses;//Display the user's score at the end of the program
cout<< " Total number of guesses: "<<guess;//Display the # of guesses by user
}
return 0;
}
ancient dragon-how do i put my source code in tags?
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <string>
using namespace std;
int main()
{
srand ( static_cast<unsigned int> ( time ( 0 ) ) );
int randNum = rand() % 100 + 1;
int num = 0;
int wins = 0;
int losses = 0;
int guess=0;
string uname;
cout<<"Please enter your name: ";
getline ( cin, uname );
cout<< uname <<'\n';
cout<<"Welcome to the Random Number Guessing Game!!\n";
{
do
{
// Loops until user finds the number
cout <<uname<<" "<<"please enter your choice between (#1 - 100): ";
cin >> num; // User's input of guessed number
if (num < randNum) // If num is < than the random number, inform player to try again.
cout <<uname<<" "<<"Your number was too low-please try again!";
else
if (num > randNum) // If num is > than the random number, inform player to try again.
cout<<uname<<" "<<"Your number was too high-please try again!"<< endl;
else
break;
} while (num != randNum);
wins++;
guess++;
cout<<uname<<endl;
cout<<" "<< "Excellent Job!! Your number is correct!!"<< endl;//Informs if the player is successfull
cout << "Your total wins: " << wins;//Display the user's score at the end of the program
cout << " Your total losses: " << losses;//Display the user's score at the end of the program
cout<< " Total number of guesses: "<<guess;//Display the # of guesses by user
}
return 0;
}
-------------------------------------------------------
We haven't spoken about nested loops in class as of yet-i guess we'll do so …
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <string>
using namespace std;
int main()
{
srand(time(0));
int randNum = rand() % 100 + 1; // Generates random number between 1 and 100
int num = 0;
int wins = 0;
int losses = 0;
int tries = 0;
string uname;
cout <<"Please enter your name:"<<endl;//Request name of player.
getline (cin,uname);
cout<<uname<<endl;
cout <<"Welcome to the Random Number Guessing Game!!"<<endl; // Name of Game.
do
{
// Loops until user finds the number
cout <<uname<<" "<<"Enter your choice on the keyboard (#1 - 100): ";
cin >> num; // User's input of guessed number
if (num < randNum) // If num is < than the random number, inform player to try again.
cout <<uname<<""<<"Your number was too low-please try again!"<< endl;
{
wins = wins ++;
break;
}
if (num > randNum) // If num is > than the random number, inform player to try again.
cout<<uname<<""<<"Your number was too high-please try again!"<< endl;
else
tries = tries ++;
} while (num != randNum); // Informs player if their number is correct.
cout<<uname<<endl;
cout<<" "<< "Excellent Job!! Your number is correct!!"<< endl;//Informs if the player is successfull
cout << "Your total wins: " << wins;//Display the user's score at the end of the program
cout << " Your total losses: " << losses;//Display the user's score at the end of the program
return 0;
}
I don't see what i'm doing wrong-it compiles ok...but with all the numbers …
ASSGINMENT #1
Accounting teachers, being naturally inept with numbers, have a difficult time calculating students’ averages and assigning letter grades at the end of each semester. Your accounting teacher is no exception. To make this end of semester grading easier, and more accurate, he hires you to write a program (C++) to automate the task. There are a variable number of students in his class, with each students grade being calculated as follows:
2 Tests 10% each
Midterm Exam 25%
Final Exam 30%
Term Project 25%
Input data is stored in a file named ClassData.dat. The first line in the input file has the number of students in the class. Each subsequent line contains one student’s Lastname, test-scores, exam scores and project score. Your program should begin by reading the number of students in the class, and then for each student, read the student’s name and test, exam and project scores. The program should then calculate the student’s average and assign him/her a letter grade ("A" for 90-100; "B" for 80-89; "C" for 70-79; and "F" for 69 and below). Finally, for each student, the program should print, to output file, his/her name, average, and grade.
Once all students have been processed, the program should print a summary report stating the number of "A"s, "B"s, "C"s and "F"s assigned.
A couple questions because I'm kinna wondering a few things.
First- I've created a Text file using notepad with the following data:
10
Isaacs 10 8 22 …
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;
int main()
{
srand(time(0));
int randNum = rand() % 100 + 1; // Generates random number between 1 and 100
int num = 0;
int name;//Name of player
cout << "Welcome to the Random Number Guessing Game!!"<<endl; // Name of Game.
cout<<"Your name is?"<<endl;//Request name of player.
do
{
// Loops until user finds the number
cout << "Enter your choice on the keyboard (#1-100): ";
cin >> num; // User's input of guessed number
if (num < randNum) // If num is < than the random number, inform player to try again.
cout <<"Your number was too low\n\n";
if (num > randNum) // If num is > than the random number, inform player to try again.
cout<<"Your number was too high\n\n";
} while (num != randNum); // Informs player if their number is correct.
cout<<"Excellent Job!! Your number is correct!!";
return 0;
}
----------------------------------------------------------------------------------
The program compiles ok-but i have a few bugs-
First-How do I get the program to request for a player's name (which will require input by player) and allow the name to be used throughout the game?
Second-How can I keep track of the user's guesses with a counter?
Third-I'm suppose to enter a score at the end of the program when the guess is right? So pretty much I'll need a tally i.e. The amount of ""Your number was too low" vs "Your number was too high".
Thanks for insight...Those were the instructions that my professor gave to me. Initially I was thinking about it also as to the assignment of the alphabet letters were like that. With regards to loops, our class has not reached that chapter yet...we are at if/else statements....I'll go through the notes and see if i can get this to work.
here is the new code that i came up with-u can disregard the one that was initially posted.
----------------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <iomanip>
using namespace std;
int main()
{
int January=1;//Months during the year.
int Febuary=2;
int March=3;
int April=4;
int May=5;
int June=6;
int July=7;
int August=8;
int September=9;
int October=10;
int November=11;
int December=12;
int 0=Q;//Days
int 1=R;
int 2=S;
int 3=T;
int 4=U;
int 5=V;
int 6=W;
int 7=X;
int 8=Y;
int 9=Z;
int Q=0;//Days
int R=1;
int S=2;
int T=3;
int U=4;
int V=5;
int W=6;
int X=7;
int Y=8;
int Z=9;
int yearA=26+1988;//Years
int yearB=25+1988;
int yearC=24+1988;
int yearD=23+1988;
int yearE=22+1988;
int yearF=21+1988;
int yearG=20+1988;
int yearH=19+1988;
int yearI=18+1988;
int yearJ=17+1988;
int yearK=16+1988;
int yearL=15+1988;
int yearM=14+1988;
int yearN=13+1988;
int yearO=12+1988;
int yearP=11+1988;
int yearQ=10+1988;
int yearR=9+1988;
int yearS=8+1988;
int yearT=7+1988;
int yearU=6+1988;
int yearV=5+1988;
int yearW=4+1988;
int yearX=3+1988;
int yearY=2+1988;
int yearZ=1+1988;
cout<<"Decode an expiration date"<<endl;
cin>>
cout<<"Encode a date"<<endl;
cin>>
cout<<decode<<endl;
return 0;
}
Product expiration dates are often encoded using numbers and letters which encode the month day and year. A common technique is to use letters instead of numbers in the dates. Assume that ACME Bakers encodes the months using letters "A" through "L", each digit of the expiration date as the three letters "Q" through "Z", (where "Q" is 0 and "Z" is 9), and the year as the letters "Z" through "A" plus 1988 (where "Z" is 1 and "A" is 26).
Your program (and all design documentation) shall present two options to the user:
First- decode an expiration code and secondly encode a date.
If the decode option is selected, your program will prompt user for an encoded expiration data from ACME Bakers and decodes it. Days of the month that have only one digit (e.g, April 3, 1993) should be printed with a single digit, not with two date digits (e.g, April 03, 1993).
If the encode option is selected, your program will accept as input a date (i.e., October 31, 1993), and encode it into the above described code (i.e., JTRV).
Your program must check for and handle incorrect date and code formats.
I'm having a problem trying to come up with statements(if/else) which could encode and decode. See what I have below, thanks for the assistance.
#include <iostream>
#include <string>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <iomanip>
using namespace std;
int main()
{
int monthA=1;//Months during the year.
int monthB=2;
int monthC=3;
int …
Thanks much for your assistance!! I got it-The program works great....You are correct. Easter sunday = March 22+d+e.
Also, if it's a leap year-it would really make much of a difference..by that i mean, the calculations like how i have it would still be able to calculate a leap year just fine...or would i have to create a program that would inform the program that a specific year is a leap year and tus do a different calculation?
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <iomanip>
using namespace std;
int main()
{
cout<< "Enter the year you wish to inquire about";
int x;//The year for which it is desired to compute Easter Sunday.
int month;//Month of easter sunday.
cin>> x;//The 4-digit year.
if (x<0001 || x>9999)
cout<<"The year has to be between 0001 & 9999"<<endl;
int a = x % 19;//The remainder of the division of x by 19.
int b = x % 4;//The remainder of the division of x by 4.
int c = x % 7;//The remainder of the division of x by 7.
int d = (19 * a + 24) % 30;//The remainder of the division of (19*a + 24) by 30.
int e = (2 * b + 4 * c + 6 * d + 5) % 30;//The remainder of the division of (2*b+4*c+6*d+5) by 7.
int sunday = (22 + d + e);//The calculation of easter sunday.
if( sunday > 334)
{
month = 12; // Dec
}
else if( sunday > 304)
{
month = 11; // Nov
}
else if (sunday > 273)
{
month = 10; //Oct
}
else if( sunday > 242 )
{
month = 9; // Sep
}
else if (sunday > 211)
{
month = 8; //Aug
}
else if( sunday > 180)
{
month = 7; // Jul
}
else if (sunday > 150)
{
month = 6; //Jun
}
else if( sunday > 119) …