简体   繁体   中英

print the content of 3 dimension array in c++ .. its dimensions 1st come from index and 2nd from another array and 3rd from another array?

from the code below i want to make table"array" that hold in row 3 value 1 - sub_num'subject number' 2 - and it's mark"from the array" 3 - and it's grade "from the last array"

to be something like this the wanted outcome i'm bigginer to c++ and struggle in this

#include <iostream>
#include <istream>
#include <cstdio>

using namespace std;

int main(){
//-----------------------------the 1st dimension-------------------------
int sub_num;
cout<<"enter number of subject registered this semester : ";
cin>>sub_num;

//-----------------------------the 2nd dimension-------------------------
float mark[sub_num];
    for(int m=1; m<sub_num+1; m++){
            printf("\n \t Enter marks that you obtained in subject number %d :",m);
            cin>>mark[m];
    }

//-----------------------------the 3rd dimension-------------------------
char *grade[sub_num];
    for(int i=0; i<sub_num; i++){
        if(mark[i]>80)
    {
        grade[i]="E";
    }
    else if(mark[i]>60 && mark[i]<=80)
    {
        grade[i]="V";
    }
    else if(mark[i]>50 && mark[i]<=60)
    {
        grade[i]="G";
    }
    else if(mark[i]>40 && mark[i]<=50)
    {
        grade[i]="P";
    }
    else {
        grade[i]="f";
    }
    }

I figure out a solution, it simply adds this 2 line to the code:D

for (int i=0; i<sub_num; i++){
    cout<<i<<"\t"<<mark[i]<<"\t"<<grade[i]<<"\n";

I think I have to try more befor asking XD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM