|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Sorry for the minor problem but I need help!! I need to hand in this program in a few hours but I can't seem to find the parce error!!!
Code:
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
int a;
int num[3][3];
srand((unsigned)time(NULL));
a = rand() % (7 + 1); /* getting random numbers 0-7*/
switch(a){
case 0: /* if a=0 and so on*/
num[3][3]={{8, 1, 6}, {3, 5, 7}, {4, 9, 2}};
printf("%d", num[3][3]);
break;
case 1:
num[3][3]={{4, 3, 8}, {9, 5, 1}, {2, 7, 6}};
printf("%d", num[3][3]);
break;
case 2:
num[3][3]={{2, 9, 4}, {7, 5, 3}, {6, 1, 8}};
printf("%d", num[3][3]);
break;
case 3:
num[3][3]={{6, 7, 2}, {1, 5, 9}, {8, 3, 4}};
printf("%d", num[3][3]);
break;
case 4:
num[3][3]={{6, 1, 8}, {7, 5, 3}, {2, 9, 4}};
printf("%d", num[3][3]);
break;
case 5:
num[3][3]={{8, 3, 4}, {1, 5, 9}, {6, 7, 2}};
printf("%d", num[3][3]);
break;
case 6:
num[3][3]={{4, 9, 2}, {3, 5, 7}, {8, 1, 6}};
printf("%d", num[3][3]);
break;
case 7:
num[3][3]={{2, 7, 6}, {9, 5, 1}, {4, 3, 8}};
printf("%d", num[3][3]);
break;
}
}
Code:
Æ@DDK5LN1X ~
$ gcc 56.c
56.c: In function `main':
56.c:14: error: parse error before '{' token
56.c:18: error: parse error before '{' token
56.c:22: error: parse error before '{' token
56.c:26: error: parse error before '{' token
56.c:30: error: parse error before '{' token
56.c:34: error: parse error before '{' token
56.c:38: error: parse error before '{' token
56.c:42: error: parse error before '{' token
sorry for such a newbie question and program All it is doing is randomly showing the possible answers to a 3x3 magic square according to the random number that is generated and inserted into int a. |
| Sponsored Links |
|
|
|
|||||
|
You can not give new values to arrays, using the {}-operators. You can only do that, when you're initializing. You've to use the =-operator explicit.
Code:
num[3][3] = 8; // Allowed
num[3][3] = {{8, 1, 6}, {3, 5, 7}, {4, 9, 2}}; // Disallowed
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum C/C++ resources - C/C++ frequently asked questions Python resources - Python frequently asked questions I'm always up for a chat, so feel free to contact me... |
|
|||
|
thank you v0id for helping me everytime!!! It's always very helpful and I learned what I was doing wrong, but it still isn't working. This is what I've changed so far..
Code:
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
int a,i,j;
int num[2][2];
srand((unsigned)time(NULL));
a = rand() % (7 + 1);
switch(a){
case 0:
num[0][0]=8;
num[0][1]=1;
num[0][2]=6;
num[1][0]=3;
num[1][1]=5;
num[1][2]=7;
num[2][0]=4;
num[2][1]=9;
num[2][2]=2;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
printf("%3d",num[i][j]);}}
break;
case 1:
num[0][0]=4;
num[0][1]=3;
num[0][2]=8;
num[1][0]=9;
num[1][1]=5;
num[1][2]=1;
num[2][0]=2;
num[2][1]=7;
num[2][2]=6;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
printf("%3d",num[i][j]);}}
break;
case 2:
num[0][0]=2;
num[0][1]=9;
num[0][2]=4;
num[1][0]=7;
num[1][1]=5;
num[1][2]=3;
num[2][0]=6;
num[2][1]=1;
num[2][2]=8;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
printf("%3d",num[i][j]);}}
break;
case 3:
num[0][0]=6;
num[0][1]=7;
num[0][2]=2;
num[1][0]=1;
num[1][1]=5;
num[1][2]=9;
num[2][0]=8;
num[2][1]=3;
num[2][2]=4;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
printf("%3d",num[i][j]);}}
break;
case 4:
num[0][0]=6;
num[0][1]=1;
num[0][2]=8;
num[1][0]=7;
num[1][1]=5;
num[1][2]=3;
num[2][0]=2;
num[2][1]=9;
num[2][2]=4;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
printf("%3d",num[i][j]);}}
break;
case 5:
num[0][0]=8;
num[0][1]=3;
num[0][2]=4;
num[1][0]=1;
num[1][1]=5;
num[1][2]=9;
num[2][0]=6;
num[2][1]=7;
num[2][2]=2;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
printf("%3d",num[i][j]);}}
break;
case 6:
num[0][0]=4;
num[0][1]=9;
num[0][2]=2;
num[1][0]=3;
num[1][1]=5;
num[1][2]=7;
num[2][0]=8;
num[2][1]=1;
num[2][2]=6;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
printf("%3d",num[i][j]);}}
break;
case 7:
num[0][0]=2;
num[0][1]=7;
num[0][2]=6;
num[1][0]=9;
num[1][1]=5;
num[1][2]=1;
num[2][0]=4;
num[2][1]=3;
num[2][2]=8;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
printf("%3d",num[i][j]);}}
break;
}
}
|
|
|||||
|
I've responded to your other thread. In the response I provided an example, including how to fill and print matrices.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum C/C++ resources - C/C++ frequently asked questions Python resources - Python frequently asked questions I'm always up for a chat, so feel free to contact me... |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VB6.0:Tutorial, Error handling | TcM | VB Tutorials | 9 | 06-06-2008 01:31 PM |
| Download problem, internal Server Error | j3cubcapt | ionFiles | 1 | 07-02-2007 09:45 AM |
| Php - CGI Error | thesquirrel16 | General Programming | 1 | 05-19-2007 05:09 PM |
| can someone help me with my c librarys? | bobwrit | C and C++ | 4 | 04-27-2007 06:19 PM |
| Php error handling | Jaan | PHP Tutorials | 1 | 03-01-2007 09:20 PM |
| John | ........ | 223.00000 |
| dargueta | ........ | 168.00000 |
| Xav | ........ | 164.00000 |
| gaylo565 | ........ | 18.00000 |
| WingedPanther | ........ | 15.00000 |
| |pH| | ........ | 15.00000 |
| Johnnyboy | ........ | 3.00000 |
| navghost | ........ | 1.00000 |
Goal: 100,000 Posts
Complete: 66%