- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- 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
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
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-02-2002 06:11 PM
тАО12-02-2002 06:11 PM
i think i can make a temp variable, but how?
#include
int main(int argc,char*argv[])
{
int ch;
int c;
int iJunk;
c = 0;
ch = ' ';
printf("\nEnter Grade For Quiz 1:\n");
scanf("%d",&c);
ch = getc(stdin);
printf("\nEnter Grade For Quiz 2:\n");
scanf("%d",&c);
ch = getc(stdin);
printf("\nEnter Grade For Quiz 3:\n");
scanf("%d",&c);
ch = getc(stdin);
printf("\nEnter Grade For Test 1:\n");
scanf("%d",&c);
ch = getc(stdin);
printf("\nEnter Grade For Test 2:\n");
scanf("%d",&c);
ch = getc(stdin);
if(c>=90)
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");
ch = getc(stdin);
return 0;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 07:54 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 08:26 PM
тАО12-02-2002 08:26 PM
Re: C Program, im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 08:34 PM
тАО12-02-2002 08:34 PM
Re: C Program, im stuck
Use an array for the scores or
declare another int
int tot;
then after each getc(stdin) line do this:
tot += c;
then before the IF tests do this:
c = tot / 5;
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 08:55 PM
тАО12-02-2002 08:55 PM
Re: C Program, im stuck
#include
int main(int argc,char*argv[])
{
int ch;
int c;
int iJunk;
int tot;
c = 0;
ch = ' ';
printf("\nEnter Grade For Quiz 1:\n");
scanf("%d",&c);
ch = getc(stdin);
tot += c;
printf("\nEnter Grade For Quiz 2:\n");
scanf("%d",&c);
ch = getc(stdin);
tot += c;
printf("\nEnter Grade For Quiz 3:\n");
scanf("%d",&c);
ch = getc(stdin);
tot += c;
printf("\nEnter Grade For Test 1:\n");
scanf("%d",&c);
ch = getc(stdin);
tot += c;
printf("\nEnter Grade For Test 2:\n");
scanf("%d",&c);
ch = getc(stdin);
tot += c;
c = tot / 5;
if(c>=90)
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");
ch = getc(stdin);
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 09:10 PM
тАО12-02-2002 09:10 PM
Re: C Program, im stuck
Let me know if you need more help in modifying it.
#include
#include
#define MAX 10
main(argc,argv)
int argc;
char *argv[];
{
int i,j, buff[MAX], k, avr;
k=0;
if(argc != 2){
printf("Usage: %s
exit(1);
}
i = atof(argv[1]);
for(j=0;j printf("Enter the Marks for Quiz %d:", (j+1));
scanf("%d", &buff[j]);
}
for(j=0;j k=k+buff[j];
avr = k/i;
if(avr>80)
printf("You have Got Grade A\n");
if((avr>60) && (avr<80))
printf("You have Got Grade B\n");
if((avr>40) && (avr<60))
printf("You have Got Grade C\n");
if(avr<40)
printf("You Have failed\n");
printf("Average=%d\n", avr);
}
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 10:24 PM
тАО12-02-2002 10:24 PM
Re: C Program, im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 10:26 PM
тАО12-02-2002 10:26 PM
Re: C Program, im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 10:31 PM
тАО12-02-2002 10:31 PM
Re: C Program, im stuck
the code posted by Rajeev works fine!
Did you compile the program?
==============================
L1000: home/yogeeraj>cc test2.c
/usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file (test2.o) was detected. The linked output may not run on a PA 1.x system.
L1000: home/deg>a.out
Usage: a.out
L1000: home/yogeeraj>a.out 11
Enter the Marks for Quiz 1:12
Enter the Marks for Quiz 2:12
Enter the Marks for Quiz 3:34
Enter the Marks for Quiz 4:45
Enter the Marks for Quiz 5:67
Enter the Marks for Quiz 6:34
Enter the Marks for Quiz 7:67
Enter the Marks for Quiz 8:34
Enter the Marks for Quiz 9:67
Enter the Marks for Quiz 10:345
Enter the Marks for Quiz 11:345
You have Got Grade A
Average=193
L1000: home/yogeeraj>
==============================
Why don't describe your problem with an example?
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 10:37 PM
тАО12-02-2002 10:37 PM
Re: C Program, im stuck
the code posted by Rajeev works fine!
Did you compile the program?
==============================
L1000: home/yogeeraj>cc test2.c
/usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file (test2.o) was detected. The linked output may not run on a PA 1.x system.
L1000: home/deg>a.out
Usage: a.out
L1000: home/yogeeraj>a.out 11
Enter the Marks for Quiz 1:12
Enter the Marks for Quiz 2:12
Enter the Marks for Quiz 3:34
Enter the Marks for Quiz 4:45
Enter the Marks for Quiz 5:67
Enter the Marks for Quiz 6:34
Enter the Marks for Quiz 7:67
Enter the Marks for Quiz 8:34
Enter the Marks for Quiz 9:67
Enter the Marks for Quiz 10:345
Enter the Marks for Quiz 11:345
You have Got Grade A
Average=193
L1000: home/yogeeraj>
==============================
Why don't describe your problem with an example?
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 10:44 PM
тАО12-02-2002 10:44 PM
Re: C Program, im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 10:48 PM
тАО12-02-2002 10:48 PM
Re: C Program, im stuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 10:48 PM
тАО12-02-2002 10:48 PM
Re: C Program, im stuck
can you post the error messages you are getting?
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-02-2002 10:54 PM
тАО12-02-2002 10:54 PM
Re: C Program, im stuck
Executing g++.exe...
g++.exe "C:\My Documents\Untitled3.cpp" -o "C:\My Documents\Untitled3.exe" -g3 -I"C:\DEV-CPP\include" -I"C:\DEV-CPP\include\g++-3" -I"C:\DEV-CPP\include" -L"C:\DEV-CPP\lib"
C:\My Documents\Untitled3.cpp:4: `argc' was not declared in this scope
C:\My Documents\Untitled3.cpp:4: `argv' was not declared in this scope
C:\My Documents\Untitled3.cpp:5: ANSI C++ forbids declaration `main' with no type
C:\My Documents\Untitled3.cpp:5: initializer list being treated as compound expression
C:\My Documents\Untitled3.cpp:5: syntax error before `int'
C:\My Documents\Untitled3.cpp:7: parse error before `{'
C:\My Documents\Untitled3.cpp:9: ANSI C++ forbids declaration `k' with no type
C:\My Documents\Untitled3.cpp:10: parse error before `if'
C:\My Documents\Untitled3.cpp:12: ANSI C++ forbids declaration `exit' with no type
C:\My Documents\Untitled3.cpp:12: `int exit' redeclared as different kind of symbol
C:/DEV-CPP/include/stdlib.h:325: previous declaration of `void exit(int)'
C:\My Documents\Untitled3.cpp:13: parse error before `}'
C:\My Documents\Untitled3.cpp:14: ANSI C++ forbids declaration `i' with no type
C:\My Documents\Untitled3.cpp:14: warning: initialization to `int' from `double'
C:\My Documents\Untitled3.cpp:15: parse error before `for'
C:\My Documents\Untitled3.cpp:15: parse error before `;'
C:\My Documents\Untitled3.cpp:15: syntax error before `++'
C:\My Documents\Untitled3.cpp:17: `buff' was not declared in this scope
C:\My Documents\Untitled3.cpp:17: `j' was not declared in this scope
C:\My Documents\Untitled3.cpp:17: ANSI C++ forbids declaration `scanf' with no type
C:\My Documents\Untitled3.cpp:17: `int scanf' redeclared as different kind of symbol
C:/DEV-CPP/include/stdio.h:231: previous declaration of `int scanf(const char *, ...)'
C:\My Documents\Untitled3.cpp:17: initializer list being treated as compound expression
C:\My Documents\Untitled3.cpp:18: parse error before `}'
C:\My Documents\Untitled3.cpp:19: parse error before `;'
C:\My Documents\Untitled3.cpp:19: syntax error before `++'
C:\My Documents\Untitled3.cpp:21: ANSI C++ forbids declaration `avr' with no type
C:\My Documents\Untitled3.cpp:22: parse error before `if'
C:\My Documents\Untitled3.cpp:30: ANSI C++ forbids declaration `printf' with no type
C:\My Documents\Untitled3.cpp:30: `int printf' redeclared as different kind of symbol
C:/DEV-CPP/include/stdio.h:211: previous declaration of `int printf(const char *, ...)'
C:\My Documents\Untitled3.cpp:30: initializer list being treated as compound expression
C:\My Documents\Untitled3.cpp:31: parse error before `}'
C:\My Documents\Untitled3.cpp:6: storage size of `argv' isn't known
Execution terminated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-03-2002 04:36 AM
тАО12-03-2002 04:36 AM
Re: C Program, im stuck
First, you didn't initialize 'tot' to 0 at the beginning, so it can have any value at the beginning. So change
int tot;
to
int tot = 0;
Second syntax of your main() in the second try is quite old and looks like your compiler do not accept it. So instead of:
main(argc argv)
int argc;
char *argv[];
{
try:
int main( int argc, char *argv[] )
{
Good luck
Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-03-2002 08:21 AM
тАО12-03-2002 08:21 AM
Re: C Program, im stuck
here is the bug
-I"C:\DEV-CPP\include" -L"C:\DEV-CPP\lib"
C:\My Documents\Untitled2.cpp: In function `int main(int, char **)':
C:\My Documents\Untitled2.cpp:18: warning: assignment to `int' from `double'
Execution terminated
Compilation successful
can anyone help me with this?
#include
#include
#define MAX 10
int main(int argc,char*argv[])
{
int i,j, buff[MAX], k, avr;
int iJunk;
k=0;
if(argc != 2){
printf("Usage: %s
iJunk = getchar();
exit(1);
}
i = atof(argv[1]);
for(j=0;jprintf("Enter the Marks for Quiz %d:", (j+1));
scanf("%d", &buff[j]);
}
for(j=0;jk=k+buff[j];
avr = k/i;
if(avr>80)
printf("You have Got Grade A\n");
if((avr>60) && (avr<80))
printf("You have Got Grade B\n");
if((avr>40) && (avr<60))
printf("You have Got Grade C\n");
if(avr<40)
printf("You Have failed\n");
printf("Average=%d\n", avr);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-03-2002 10:41 AM
тАО12-03-2002 10:41 AM
Re: C Program, im stuck
Mikel,
on line 18 you are using atof() which is converting a string to a double-float, so assigning it to a "int" isn't cutting it.
I think you want the "atoi" function.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-03-2002 11:30 AM
тАО12-03-2002 11:30 AM
Re: C Program, im stuck
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");
ch = getc(stdin);
because i need the quizes to average out seperatly, and the same for the tests. and then add it to the program below, someone please help. me head hurts!!! lol
#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;
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();
}
printf("\n");
printf("Press a key to continue...\n");
iJunk = getchar();
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-03-2002 11:31 AM
тАО12-03-2002 11:31 AM