- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Part II C program im stuck
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2002 12:05 PM
12-03-2002 12:05 PM
something like this
=(quizavg * 0.30)+(testsavg * 0.70)
if(c>=90)
then give it a final grade from the weighted grade. anyhelp with this?
printf("You get an A\n");
else if((c>=80)&&(c<89))
printf("You get a B\n");
else if((c>=70)&&(c<79))
printf("You get a C\n");
else if((c>=60)&&(c<69))
printf("You get a D\n");
else
printf("Failed the class\n");
#include
struct student_info{
char fname[26];
char lname[31];
int quiza[4];
int quizb[4];
int quizc[4];
int testa[4];
int testb[4];
};
typedef struct student_info SI;
int main()
{
SI student[5];
int iJunk;
int iCount;
int quiztot;
int quizavg;
int testtot;
int testavg;
for (iCount = 0; iCount < 3; iCount++){
printf("Students First Name:");
scanf("%s", student[iCount].fname );
iJunk = getchar();
printf("Students Last Name:");
scanf("%s", student[iCount].lname );
iJunk = getchar();
printf("Score for Quiz 1:");
scanf("%d", &student[iCount].quiza );
iJunk = getchar();
printf("Score for Quiz 2:");
scanf("%d", &student[iCount].quizb );
iJunk = getchar();
printf("Score For Quiz 3:");
scanf("%d", &student[iCount].quizc );
iJunk = getchar();
printf("Score For Test 1:");
scanf("%d", &student[iCount].testa );
iJunk = getchar();
printf("Score For Test 2:");
scanf("%d", &student[iCount].testb );
iJunk = getchar();
quiztot = SI.quiza + SI.quizb + SI.quizc;
quizavg = quiztot/3;
testtot = SI.testa + SI.testb;
testavg = testtot/2;
}
printf("\n");
printf("Press a key to continue...\n");
iJunk = getchar();
return 0;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2002 02:47 PM
12-03-2002 02:47 PM
Re: Part II C program im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2002 03:49 PM
12-03-2002 03:49 PM
SolutionSeems to me you have defined a datastructure type called SI then made an instance of it called student[].
You then went through a routine which filled student[] with info from keyboard input. I assume this part works OK.
Now you say
"quiztot = SI.quiza + SI.quizb + SI.quizc;
quizavg = quiztot/3; "
But SI is now the type and not the student[] so it is not clear to me what SI.testa refers to. I would think you would need to say:
quiztot = student[iCount].quiza + student[iCount].quizb + student[iCount].quizc
Ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2002 03:52 PM
12-03-2002 03:52 PM
Re: Part II C program im stuck
#include
struct data {
char fname[26];
char lname[31];
int quiza, quizb, quizc, testa, testb, grade;
};
main()
{
struct data student[3];
int i, q_total, t_total, q_avg, t_avg;
for (i=0; i<3; i++){
printf("Enter the record No. %d\n", (i+1));
printf("Enter the Students first Name & Second Name: ");
scanf("%s %s", &student[i].fname, &student[i].lname);
printf("Enter the Marks %s %s Got in Quiz A: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].quiza);
printf("Enter the Marks %s %s Got in Quiz B: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].quizb);
printf("Enter the Marks %s %s Got in Quiz C: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].quizc);
printf("Enter the Marks %s %s Got in Test 1: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].testa);
printf("Enter the Marks %s %s Got in Test 2: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].testb);
q_avg = ((student[i].quiza)+(student[i].quizb)+(student[i].quizc))/3;
t_avg = ((student[i].testa)+(student[i].testb))/2;
student[i].grade = (q_avg*0.3)+(t_avg*0.7);
if((student[i].grade)>80)
printf("You have Got Grade A\n");
if((student[i].grade)>60 && (student[i].grade)<80)
printf("You have Got Grade B\n");
if((student[i].grade)>40 && (student[i].grade)<60)
printf("You have Got Grade C\n");
if((student[i].grade)<40)
printf("You Have failed\n");
printf("Average=%d\n", (student[i].grade));
}
puts("");
printf("________________________________________________\n");
for (i=0; i<3; i++)
printf("Entry No: %d, \n\t\t Name: %s %s\n\t\t Grade:%d\n", (i+1), student[i].fname, student[i].lname, student[i].grade);
printf("________________________________________________\n");
}
Let me know if u need more help.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2002 04:17 PM
12-03-2002 04:17 PM
Re: Part II C program im stuck
also if i wanted to get a average grade of everyone i entered how do i do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2002 04:24 PM
12-03-2002 04:24 PM
Re: Part II C program im stuck
Just compile and try running it you'll know what is does.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2002 06:20 PM
12-03-2002 06:20 PM
Re: Part II C program im stuck
%s %s\n\t\t
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2002 06:42 PM
12-03-2002 06:42 PM
Re: Part II C program im stuck
Thats for a "TAB" singe \t is single TAB. This is used to have a formatted output on the screen.
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2002 09:24 PM
12-03-2002 09:24 PM
Re: Part II C program im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 12:05 AM
12-04-2002 12:05 AM
Re: Part II C program im stuck
The structure element grade has all data for the class so make a loop and add all the elements and divide by number of students which you have defined as 3.
for(i=0;i<3;i++)
sum+=(student[i].grade);
av_class_grade=(sum)/3;
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 06:19 AM
12-04-2002 06:19 AM
Re: Part II C program im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 05:16 PM
12-04-2002 05:16 PM
Re: Part II C program im stuck
for(iCount=0;iCount<3;iCount++)
sum+=(student[iCount].grade);
av_class_grade=(sum)/3;
if((av_class_grade)>90)//Gives letter grade
printf("They have a A\n", student[iCount].fname, student[iCount].lname);
else if((av_class_grade=(sum))>80 && (av_class_grade=(sum))<= 90)
printf("They have a B\n");
else if((av_class_grade=(sum))>70 && (av_class_grade=(sum))<= 80)
printf("They have a C\n");
else if((av_class_grade=(sum))>60 && (av_class_grade=(sum))<= 70)
printf("They have a D\n");
else if((av_class_grade=(sum))<60)
printf("They failed the class\n");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 05:17 PM
12-04-2002 05:17 PM
Re: Part II C program im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 05:49 PM
12-04-2002 05:49 PM
Re: Part II C program im stuck
int sum, av_class_grade;
after #include
and then just at the end add the following code
sum=0;
for(i=0;i<3;i++)
sum+=(student[i].grade);
av_class_grade=(sum)/3;
printf("%d %d\n", av_class_grade, sum);
if(av_class_grade>80)
printf("The Class has Got Grade A\n");
if(av_class_grade>60 && av_class_grade<80)
printf("The Class has Got Grade B\n");
if(av_class_grade>40 && av_class_grade<60)
printf("The Class has Got Grade C\n");
if(av_class_grade<40)
printf("The Class has failed\n");
it should work.
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 06:28 PM
12-04-2002 06:28 PM
Re: Part II C program im stuck
could i just make a variable for the students so ican add more than 3?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 06:40 PM
12-04-2002 06:40 PM
Re: Part II C program im stuck
main(argc, argv)
int argc;
char *argv[];
{
if (argc != 2){
printf("Usage: %s
exit(1);
}
Then continue with the normal codes...
cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 06:48 PM
12-04-2002 06:48 PM
Re: Part II C program im stuck
im having problems with it printing to the final output. it gives some funky numbers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 06:59 PM
12-04-2002 06:59 PM
Re: Part II C program im stuck
no of student say x=atoi(argv[1]);
and then u'll have to change the student count from 3 to the x variable where ever you are doing for(i=0;i<3...make x
The program should be fine after that.
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 08:15 PM
12-04-2002 08:15 PM
Re: Part II C program im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 08:45 PM
12-04-2002 08:45 PM
Re: Part II C program im stuck
#include
int sum, av_class_grade;
struct data {
char fname[26];
char lname[31];
int quiza, quizb, quizc, testa, testb, grade;
};
main(argc, argv)
int argc;
char *argv[];
{
struct data student[3];
int i, q_total, t_total, q_avg, t_avg;
int x;
if(argc != 2){
printf("Usage: %s
exit(1);
}
x=atoi(argv[1]);
for (i=0; i
printf("Enter the Students first Name & Second Name: ");
scanf("%s %s", &student[i].fname, &student[i].lname);
printf("Enter the Marks %s %s Got in Quiz A: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].quiza);
printf("Enter the Marks %s %s Got in Quiz B: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].quizb);
printf("Enter the Marks %s %s Got in Quiz C: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].quizc);
printf("Enter the Marks %s %s Got in Test 1: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].testa);
printf("Enter the Marks %s %s Got in Test 2: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].testb);
q_avg = ((student[i].quiza)+(student[i].quizb)+(student[i].quizc))/3;
t_avg = ((student[i].testa)+(student[i].testb))/2;
student[i].grade = (q_avg*0.3)+(t_avg*0.7);
if((student[i].grade)>80)
printf("You have Got Grade A\n");
if((student[i].grade)>60 && (student[i].grade)<80)
printf("You have Got Grade B\n");
if((student[i].grade)>40 && (student[i].grade)<60)
printf("You have Got Grade C\n");
if((student[i].grade)<40)
printf("You Have failed\n");
printf("Average=%d\n", (student[i].grade));
}
puts("");
printf("________________________________________________\n");
for (i=0; i
printf("________________________________________________\n");
sum=0;
for(i=0;i
av_class_grade=(sum)/3;
if(av_class_grade>80)
printf("The Class has Got Grade A\n");
if(av_class_grade>60 && av_class_grade<80)
printf("The Class has Got Grade B\n");
if(av_class_grade>40 && av_class_grade<60)
printf("The Class has Got Grade C\n");
if(av_class_grade<40)
printf("The Class has failed\n");
}
Just copy and run this with number of students as argument.
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 09:02 PM
12-04-2002 09:02 PM
Re: Part II C program im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 09:16 PM
12-04-2002 09:16 PM
Re: Part II C program im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 09:19 PM
12-04-2002 09:19 PM
Re: Part II C program im stuck
I can attach the program thats maximum i can do or else you might have to refer for some books.
Or contact some consultant to make some custom program for you.
Attached is the program which works fine for me.
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 09:26 PM
12-04-2002 09:26 PM
Re: Part II C program im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2002 09:32 PM
12-04-2002 09:32 PM
Re: Part II C program im stuck
using cc comand
Cheers
Rajeev