| | |
weird ascii character on cout and fout
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 51
Reputation:
Solved Threads: 0
the char character for grade are coming up with weird ascii like characters instead of the letter grades. Please help!
//declaration
string first, last;
int prog1, prog2,prog3,prog4, prog5, test1, test2;
int totalpts, progavg, testavg, courseavg;
char grade;
//executables
totalpts = (prog1+prog2+prog3+prog4+prog5+test1+test2);
progavg = (prog1+prog2+prog3+prog4+prog5)/5;
testavg = (test1+test2)/2;
courseavg = (progavg+testavg)/2;
if (courseavg >=90 )grade=='A';
else if (courseavg <= 89 )grade=='B';
else if (courseavg <=79 )grade=='C';
else grade=='F';
cout<<left<<setw(20)<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
cout<<right<<setw(26)<<"Points"<<setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
Instead of showing up the letter grades, everytime the program run, it will come up with new ascii like weird character. Any help would be much appreciated! Thanks
//declaration
string first, last;
int prog1, prog2,prog3,prog4, prog5, test1, test2;
int totalpts, progavg, testavg, courseavg;
char grade;
//executables
totalpts = (prog1+prog2+prog3+prog4+prog5+test1+test2);
progavg = (prog1+prog2+prog3+prog4+prog5)/5;
testavg = (test1+test2)/2;
courseavg = (progavg+testavg)/2;
if (courseavg >=90 )grade=='A';
else if (courseavg <= 89 )grade=='B';
else if (courseavg <=79 )grade=='C';
else grade=='F';
cout<<left<<setw(20)<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
cout<<right<<setw(26)<<"Points"<<setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
Instead of showing up the letter grades, everytime the program run, it will come up with new ascii like weird character. Any help would be much appreciated! Thanks
•
•
Join Date: Oct 2009
Posts: 51
Reputation:
Solved Threads: 0
0
#3 Oct 24th, 2009
I even tried this
courseavg = (prog1+prog2+prog3+prog4+prog5+test1+test2)/7;
but.. still got weird characters for grade.
Everything else works just fine as far as it goes with showing up the right numbers except the grade letter!
courseavg = (prog1+prog2+prog3+prog4+prog5+test1+test2)/7;
but.. still got weird characters for grade.
Everything else works just fine as far as it goes with showing up the right numbers except the grade letter!
0
#5 Oct 24th, 2009
hint :
is not the same as
[/code]
C++ Syntax (Toggle Plain Text)
int x = 0, y = 0; int t = x + y;
C++ Syntax (Toggle Plain Text)
int x, y; int t = x + y
Go ahead and try to solve this euler problem, if u can. Check with me for hints and answers. Good Luck
•
•
Join Date: Oct 2009
Posts: 51
Reputation:
Solved Threads: 0
0
#6 Oct 24th, 2009
•
•
•
•
well..don't you need to ask the user to input numbers so the program can calculate the result? Right now it looks as though your just trying to add words..
The program works just fine except for the grade letter.
•
•
Join Date: Oct 2009
Posts: 51
Reputation:
Solved Threads: 0
0
#7 Oct 24th, 2009
•
•
•
•
hint :
is not the same asC++ Syntax (Toggle Plain Text)
int x = 0, y = 0; int t = x + y;
[/code]C++ Syntax (Toggle Plain Text)
int x, y; int t = x + y
Last edited by amishraa; Oct 24th, 2009 at 11:47 pm. Reason: oh.. this by the way is fstream so I am not prompting user to enter the score but reading pre-populated one from txt file.
0
#8 Oct 25th, 2009
•
•
•
•
I am not following you if you don't mind explaining where you see an error please.

As well, all of the code would be helpful, even the heading files. (yes I know that they are <iomanip>, <iostream>, <string>, etc. But it may help to just include them anyway.)
Last edited by restrictment; Oct 25th, 2009 at 12:41 am.
•
•
Join Date: Oct 2009
Posts: 51
Reputation:
Solved Threads: 0
0
#9 Oct 25th, 2009
•
•
•
•
I think he just talking about initializing that variables. Anyway...could you include the resource file that you are using, so I can accurately test out the program?
As well, all of the code would be helpful, even the heading files. (yes I know that they are <iomanip>, <iostream>, <string>, etc. But it may help to just include them anyway.)
#include<fstream>
#include<iomanip>
using namespace std;
int main(){
string first, last;
int prog1, prog2,prog3,prog4, prog5, test1, test2;
int totalpts, progavg, testavg, courseavg;
char grade;
ifstream fin;
ofstream fout;
fin.open("students.txt");
fout.open("output.txt");
if(!fin){
cout<<"Input Failure"<<endl;
system("pause");
return 1;
} //end of error check
if(!fout){
cout<<"Output Failure"<<endl;
system("pause");
return 1;
}
cout<<"Press any key to read input and calculate the grades of all students"<<endl;
cin.get(); //waits for the user to press any key
cout<<"1234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
cout<<"======================================================================"<<endl;
cout<<left<<setw(20)<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
cout<<right<<setw(26)<<"Points"<<setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
cout<<"----------------------------------------------------------------------"<<endl;
fout<<"======================================================================"<<endl;
fout<<left<<setw(20)<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
fout<<right<<setw(26)<<"Points"<<setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
fout<<"----------------------------------------------------------------------"<<endl;
while(fin){
fin>>first>>last>>prog1>>prog2>>prog3>>prog4>>prog5>>test1>>test2;
totalpts = (prog1+prog2+prog3+prog4+prog5+test1+test2);
progavg = (prog1+prog2+prog3+prog4+prog5)/5;
testavg = (test1+test2)/2;
courseavg = (progavg+testavg)/2;
if (courseavg >=90 )grade='A';
else if (courseavg <= 89 )grade='B';
else if (courseavg <=79 )grade='C';
else grade='F';
cout<<fixed<<showpoint<<setprecision(2);
cout<<left<<setw(20)<<first+" "+last<<setw(10)<<totalpts<<setw(10)<<progavg<<setw(10)<<testavg<<setw(10)<<courseavg<<setw(10)<<grade<<endl;
fout<<left<<setw(20)<<first+" "+last<<setw(10)<<totalpts<<setw(10)<<progavg<<setw(10)<<testavg<<setw(10)<<courseavg<<setw(10)<<grade<<endl;
if(fin.peek()=='\n')fin.ignore();
}//end of fin controlled while
cout<<"======================================================================"<<endl;
fout<<"======================================================================"<<endl;
fin.close();
fout.close();
system("pause");
return 0;
}//end of main
Ensure the following data is saved as a txt file to the same folder where the compiler file is located:
John Doe 95 89 94 88 98 92 90
Jack Black 67 77 72 88 86 89 85
Dan Snyder 88 65 78 88 86 85 93
Sarah Peets 94 78 89 98 93 81 87
David McGregor 76 86 93 91 75 90 76
John Anderson 89 92 95 66 58 84 90
Robert Blake 85 93 84 92 90 75 94
Last edited by amishraa; Oct 25th, 2009 at 11:19 am. Reason: the "=" needs to be changed to "==" eg. if (courseavg >=90 )grade=='A';
•
•
Join Date: Oct 2009
Posts: 51
Reputation:
Solved Threads: 0
0
#10 Oct 25th, 2009
like try changing Robert Blake's numbers to even lower values
65 93 64 92 60 65 94
then the course avg comes out 76 but the letter grade still shows B
so i'm sure == is used instead of = because we don't want to assign the grade to letters but simply state that it is equal to the letters.
Only problem is the letter are showing in weird characters.. and I can't for the sake of my life figure it out!!
65 93 64 92 60 65 94
then the course avg comes out 76 but the letter grade still shows B
so i'm sure == is used instead of = because we don't want to assign the grade to letters but simply state that it is equal to the letters.
Only problem is the letter are showing in weird characters.. and I can't for the sake of my life figure it out!!
![]() |
Similar Threads
- Using a loop to display the characters for ACSII codes? HELP! (C++)
- To remove ASCII character in .TXT file (C++)
- How to find ASCII value of character in c (C)
- need help with ASCII (C++)
- Random Character Generator Help (C++)
- problem with iterator (C++)
- Validation Program (C++)
- a negative ASCII value ? (C)
Other Threads in the C++ Forum
- Previous Thread: Linker Errors..
- Next Thread: C++ runs a shell script
Views: 409 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary browser c++ c/c++ calculator char class classes code command compile compiler console constructor conversion convert count delete desktop dll dynamic encryption error file files filestream fstream function functions game givemetehcodez graph gui homework http i/o iamthwee input int lazy library link linker list loop looping math matrix member memory newbie number object objects opengl operator output parameter path pointer pointers problem program programming project random read recursion recursive reference server sort spoonfeeding string strings struct student studio template templates text time tree undefined variable vc++ vector video visual void win32 window windows winsock






