473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

no output in compiler.....why?

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?

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int main ()
  3. {
  4. /* variable definition: */
  5. char StudentName[100];
  6. float ExamValue, Sum, Avg, value;
  7. int students,exams,studentname;
  8.  
  9. // reset Sum to 0
  10. Sum =0.0;
  11. // Loop through Students
  12. while (students > 0)
  13. {
  14. printf("Enter Student Name \n");
  15. scanf("%s", StudentName);
  16.     scanf("%f", &value);
  17.     {studentname = studentname + 1; }
  18.     if (studentname < 0){
  19.     break;
  20.         printf("End of Student list");
  21.     }        
  22. // Nested Loop for Exams
  23. for (exams=0; exams < 3; exams++)
  24. {
  25. printf ("Enter exam grade: \n");
  26. scanf("%f", &ExamValue);
  27. Sum += ExamValue;
  28. }
  29. Avg = Sum/3.0;
  30. printf( "Average for %s is %f\n",StudentName,Avg);
  31. }
  32. return 0;
  33. }
Mar 31 '16 #1
5 1449
weaknessforcats
9,208 Expert Mod 8TB
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.
Mar 31 '16 #2
Do you have any examples? of what that would look like?
Apr 1 '16 #3
the Array of strings that is..
Apr 1 '16 #4
my code.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int main ()
  3. {
  4. /* variable definition: */
  5. char StudentName[100];
  6. float ExamValue, Sum, Avg, value;
  7. int students, exams, studentname;
  8.  
  9. // Loop through Students
  10. while (students > 0)
  11. {
  12. // Initialize
  13. Sum = 0.0;
  14. students = 0;
  15. studentname =0;
  16. printf("Enter Student Name \n");
  17. scanf("%s", StudentName);
  18.         studentname++; 
  19.     if (studentname < 0){
  20.     break;
  21.         printf("End of Student list \n");
  22.     }        
  23. // Nested Loop for Exams
  24. for (exams=0; exams < 3; exams++)
  25. {
  26. printf ("Enter exam grade: \n");
  27. scanf("%f", &ExamValue);
  28. Sum += ExamValue;
  29. }
  30. Avg = Sum/3.0;
  31. printf( "Average for %s is %f\n",StudentName,Avg);
  32. }
  33. return 0;
  34. }
Apr 1 '16 #5
weaknessforcats
9,208 Expert Mod 8TB
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.
Apr 2 '16 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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);
65
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...
32
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...
8
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
18
by: rajpal_jatin | last post by:
int main() { int k; union jatin{ int i :5; char j :2; }; union jatin rajpal; k= sizeof(rajpal);
31
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...
3
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...
27
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...
12
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...
2
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. ...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.