I have been tasked with making this code allow the user to enter an unspecified amount of student names and avg here 3 test grades. Once that is done I set it to end the loop when a negative number is entered. (atleast that's the plan) When the code is put into the compiler (ideone.com) it runs successfully but there is not output....why? - #include <stdio.h>
-
int main ()
-
{
-
/* variable definition: */
-
char StudentName[100];
-
float ExamValue, Sum, Avg, value;
-
int students,exams,studentname;
-
-
// reset Sum to 0
-
Sum =0.0;
-
// Loop through Students
-
while (students > 0)
-
{
-
printf("Enter Student Name \n");
-
scanf("%s", StudentName);
-
scanf("%f", &value);
-
{studentname = studentname + 1; }
-
if (studentname < 0){
-
break;
-
printf("End of Student list");
-
}
-
// Nested Loop for Exams
-
for (exams=0; exams < 3; exams++)
-
{
-
printf ("Enter exam grade: \n");
-
scanf("%f", &ExamValue);
-
Sum += ExamValue;
-
}
-
Avg = Sum/3.0;
-
printf( "Average for %s is %f\n",StudentName,Avg);
-
}
-
return 0;
-
}
5 1449
The students and studentname variables are not being initialized.
Your results will be indeterminate.
Also, the studentname array is being used for all students. You will need an array for each student. That is, an array of strings.
Do you have any examples? of what that would look like?
the Array of strings that is..
my code. - #include <stdio.h>
-
int main ()
-
{
-
/* variable definition: */
-
char StudentName[100];
-
float ExamValue, Sum, Avg, value;
-
int students, exams, studentname;
-
-
// Loop through Students
-
while (students > 0)
-
{
-
// Initialize
-
Sum = 0.0;
-
students = 0;
-
studentname =0;
-
printf("Enter Student Name \n");
-
scanf("%s", StudentName);
-
studentname++;
-
if (studentname < 0){
-
break;
-
printf("End of Student list \n");
-
}
-
// Nested Loop for Exams
-
for (exams=0; exams < 3; exams++)
-
{
-
printf ("Enter exam grade: \n");
-
scanf("%f", &ExamValue);
-
Sum += ExamValue;
-
}
-
Avg = Sum/3.0;
-
printf( "Average for %s is %f\n",StudentName,Avg);
-
}
-
return 0;
-
}
Read this: https://bytes.com/topic/c/insights/7...rrays-revealed
Post me again after you have read this and I'll provide more info.
Also scanf stops on the first whitespace character. So if your student name is Tom Cat all you will get is Tom. The Cat will show up on the next scanf wherever it is in the code. You might look up sscanf.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matthew |
last post by:
Hi,
I am using sun's CC (c++ compiler) to compile the follow code:
#define __REENTRANT
#include <stdio.h>
#include <pthread.h>
void *one(void *dummy);
|
by: Pmb |
last post by:
I'm confused as to what the compiler error message I'm getting is refering
to. Can someone take a gander and let me know what I did wrong? The program
is below. When I compile it I get the...
|
by: spibou |
last post by:
Is the output of the C preprocessor deterministic ? What I mean
by that is , given 2 compilers which conform to the same standard,
will their preprocessors produce identical output given as input...
|
by: kris |
last post by:
Hi,
I just want to know how to use the the CPPONLY pragma which causes only
the C macro preprocessor to be run. Can you specify an example.
Thanks in advance
|
by: rajpal_jatin |
last post by:
int main()
{
int k;
union jatin{
int i :5;
char j :2;
};
union jatin rajpal;
k= sizeof(rajpal);
|
by: Mark Dufour |
last post by:
Hi all,
I have recently released version 0.0.20 and 0.0.21 of Shed Skin, an
optimizing Python-to-C++ compiler. Shed Skin allows for translation of
pure (unmodified), implicitly statically typed...
|
by: gil |
last post by:
Hi,
I'm trying to find the best way to work with compiler warnings. I'd
like to remove *all* warnings from the code, and playing around with
the warning level, I've noticed that compiling with...
|
by: Dave |
last post by:
I'm having a hard time tying to build gcc 4.3.1 on Solaris using the GNU
compilers. I then decided to try to use Sun's compiler. The Sun Studio
12 compiler reports the following code, which is in...
|
by: Andreas Lundgren |
last post by:
Hi!
Is it determined that the C standard compiler always encode characters
with the same character excoding? If for example the functions Foo and
Bar are compiled by different compilers, is it...
|
by: sanjay |
last post by:
Hi All,
I have a doubt in understanding the output of the following program
that i executed on my system. I was using DevC++ IDE which uses minGW
based compiler.
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |